Question

In: Computer Science

Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and...

Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and tell whether a number is prime or not. The user chooses how many inputs go into the calculator.

For example, the code will ask the user what function they want. If the user chooses to subtract, the the code will then ask the user how many numbers they want to subtract. After, the code will ask the user to input as many numbers as they chose in the last step. Lastly, the code must subtract the first input - the second input - the third input and so on, and must print the answer.

Solutions

Expert Solution

In case of any queries, please revert back.

I have attached the screenshots below the code:-

#include <stdio.h>
#include <math.h>

int main(){
   while(1){
   int choice;
  
   printf("Please choose the operation. \n 1.Addition\n 2.subtraction\n 3.multiplication\n 4.division\n 5.Prime\n 6.End\n");
  
   scanf("%d",&choice);
  
   if(choice==6){
       break;
       }
   else if(choice==1){
       printf("Enter number of numbers to add. \n");
       int n;
       scanf("%d",&n);
       int result=0;
       for(int i=0;i<n;i++){
           printf("Enter the %d number ",i+1);
           int temp;
           scanf("%d",&temp);
           result=result+ temp;
           }
       printf("Added Result is %d\n",result);
       }
   else if(choice==2){
       printf("Enter number of numbers to subtract. \n");
       int n;
       scanf("%d",&n);
       int result=0;
       for(int i=0;i<n;i++){
           printf("Enter the %d number ",i+1);
           int temp;
           scanf("%d",&temp);
          
           if(i==0){
           result=temp;
           }
           else{
               result=result- temp;
               }
           }
       printf("Subtracted Result is %d\n",result);
       }    
   else if(choice==3){
       printf("Enter number of numbers to multiply. \n");
       int n;
       scanf("%d",&n);
       int result=1;
       for(int i=0;i<n;i++){
           printf("Enter the %d number ",i+1);
           int temp;
           scanf("%d",&temp);
           result=result* temp;
           }
       printf("Mulitiplied Result is %d\n",result);
       }
   else if(choice==4){
       printf("Enter number of numbers to Divide. \n");
       int n;
       scanf("%d",&n);
       int result;
       for(int i=0;i<n;i++){
           printf("Enter the %d number ",i+1);
           int temp;
           scanf("%d",&temp);
           if(i==0){
               result=temp;
               }
           else{  
           result=result/ temp;
           }
           }
       printf("Divided Result is %d\n",result);
       }
   else if(choice==5){
       printf("Enter number \n");
       int n,flag=1;
       scanf("%d", &n);
  
       for (int i = 2; i <= n / 2; i++) {
           if (n % i == 0) {
               flag = 0;
               break;
           }
       }
  
       if (flag == 1) {
           printf("%d is a prime number\n", n);
       }
       else {
           printf("%d is not a prime number\n", n);
       }
       }  
  
   }
   return 0;
  
   }
Screenshots:-

Activities Terminal Wed 01:00 ujjwalshadow:--/Documents/cprogs File Edit View Search Terminal Help ujjwal shadow:-/Documents/cprogs$ QCC -0 output calc.c ujjwalashadow /Documents/cprogs$ ./output Please choose the operation. 1. Addition 2. subtraction 3.nultiplication 4.division 5. Prime 6. End Enter nunber of nunbers to multiply. Enter the 1 number 58 Enter the 2 nunber 19 Enter the 3 number 10 Mulltiplled Result is 5008 Please choose the operation. 1. Addition 2. subtraction 3.multiplication 4.diviston 5. Prime 6. End Enter number of numbers to Divide. Enter the 1 number 5880 Enter the 2 number 18 Enter the 3 number 183 Divided Result is 5 Please choose the operation. 1. Addition 2. subtraction 3.nultiplication 4.division 5. Prime 6. End SOC Enter nunber 20 is not a prime number please choose the operation. 1. Addition 2. subtraction 3.multiplication 4.diviston 5. Prime 6. End ujjwalashadow:-/Documents/cprogs$

Activities Geany Wed 01:02 calc.c- /home/u]wal/Documents/cprogs - Geany File Edit Search View Document Project Build Tools Help 3sort.cpp * calcc X include <stdio.h> include chath.h> ant main whilellt int choice; printf("Please choose the operation 11 1. Addi Lionn 2.subiraclioni 3.multiplicaliun. 4.divisionin 5. Prime 6. End\n"); scanf("sd", schoice); if (choices break else if i choice printf("Enter number of numbers to add. In '); int n; scanf(" , ); int result ; forint 1-3;i<n;i++){ printf("Enter the d number 1-1); int temp; scanf( ", lemp): result result temp: printf("Added Result is dyn", result); else if choicce=2) printf("Enter number of numbers to subtract. In); int n; scant( '.n); int result-o; forint 1-3:16:14+ printf("Enter the nurber 1+11: int temp; scanf( ster): result-result. temp: printf("Subtracted Result is dyn", result); else if (choice=3){ printf "Enter number of numbers to multiply.In); int n; scanf("d",6); Status 00:557041 File /home/ u s /progs/calcit saved Come 00:55:20: File /home/ujjual/Documents/cproas/calc. saved. Messages 09:56:18: File /homerujual/Documents/cprogs/calc.c saved. 19:58:35: File /home/jjal/Documents/cprogs/calc. saved. Scribble 3:59:18: File /home/ujjual/Documents/progs/calc. saved Terminal 10 : File home l /UCuments/progs/calc. saved line: 26/96 col: 46sel: O INSTAB mode:LF encoding: UTF-Filetype: C scape: main

Activities Geany Wed 01:02 calc.c- /home/u]wal/Documents/cprogs - Geany File Edit Search View Document Project Build Tools Help 3sort.cpp * calcc * else ifichoice-41 printf("Enter nunber of numbers to Divide. \n"); int n; scanf("d",& ; int result; for(int i=0;ien: i++){ printr('Enter the number 1+1): int tep: scanf"d", terp): if(i= ) resultatetp: else result-result/ top: printf("Divided Result 15 vin' result); a else ifichoice--511 printf("Enter number n'); int n, flag=1; scand ", &11): A n / 2; i++) { for (int i = 2; i if in i = flag = 0; ) it flag - 11 printf('\ 1s a prime number\n', n); else { printf("ud is not a prin number : return ; Status00155:04: File fhome/ujjal/UCNs/pr /Calcit saved Come 00:55:20: File /home/ujjual/Documents/cproas/calc. saved. Messages 08:56:18: File /home/ujjal/Documents/cprogs/calc.c saved. 19:58:35: File /home/jjal/Documents/cprogs/calc. saved. Scribble 13:59:18: File /home/ujjual/Documents/eprogs/calc. saved. Terminal 10 : File /home /cuments/progs/calc. saved. line:26/96 col: 40 sel: DINS TAB mode:LF encoding: UTF-8 Filetype: C scape: main


Related Solutions

Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide...
Write a calculator program that prompts the user with the following menu: Add Subtract Multiply Divide Power Root Modulus Upon receiving the user's selection, prompt the user for two numeric values and print the corresponding solution based on the user's menu selection. Ask the user if they would like to use the calculator again. If yes, display the calculator menu. otherwise exit the program. EXAMPLE PROGRAM EXECUTION: Add Subtract Multiply Divide Power Root Modulus Please enter the number of the...
Implement a Java program that is capable of performingthe basic arithmetic operations (add, subtract, multiply, divide)...
Implement a Java program that is capable of performingthe basic arithmetic operations (add, subtract, multiply, divide) on binary numbers using only logical operations (i.e., not using the actual mathematical operators thatJava already supports).A skeleton for the implementation is provided and can be downloaded from Canvas.In this source file  (BinaryCalculator.java), there is already code to read stringsfrom the keyboard.  The program will exit if the string “QUIT” is received, otherwiseit will attempt to process commands of the form: <binary operand 1> <operator> <binary...
How to add, multiply, and divide numbers in flowgorithm
How to add, multiply, and divide numbers in flowgorithm
Write a Python program to add, multiply and divide any two numbers.
Write a Python program to add, multiply and divide any two numbers.
Subtract/Multiply/Divide using Significant figures 1. (16.75 - 6.2) x (9.56 x 10-19) ------------------------------------------ (6.753.2) x (8.5679...
Subtract/Multiply/Divide using Significant figures 1. (16.75 - 6.2) x (9.56 x 10-19) ------------------------------------------ (6.753.2) x (8.5679 x 1011) This is just one problem, just dividing it 2. Convert 9.64 x 1014 pm3 to nanometers
Write a C++ function template to add two inputs and return their result. Make exceptions for...
Write a C++ function template to add two inputs and return their result. Make exceptions for Characters (such that sum of two characters is a character associated with sum of their ASCII) and String (such that sum of two strings is their concatenation)
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
Variable Register a $9 b $19 c $2 C Operators + add - subtract & bitwise...
Variable Register a $9 b $19 c $2 C Operators + add - subtract & bitwise and ! bitwise or ~ bitwise not Assume the variables, a, b and c are stored in the registers given above. Give a single MIPS assembly instruction from the MIPS Core Instruction Set that performs the equivalent operation for each of the following C statements. a = ~ ( b | c ); // MIPS equivalent: -------- c = b - 2; // MIPS...
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple...
make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple times Get input from key-board and display the result in the console window
Please Use C language to Make a calculator. Make sure calculator is able to take up...
Please Use C language to Make a calculator. Make sure calculator is able to take up to 5 values. Try to make calculator using simple coding As you can. Please create a simple calculator with only +, -,* and divide. It has to be able to enter any numbers (including decimals) and be able to do the following functions: +, -, divide and multiply. Please have the answers, always rounded to two decimal figures. The calculator will also have to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT