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

PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide...
PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide using functions. It needs to ask for the two numbers from the user and will ask the user for their choice of arithmetic operation 1- subtract 2- add 3- divide 4- multiply
Using Java Write a simple calculator which can add, subtract, multiply, and divide. Here are the...
Using Java Write a simple calculator which can add, subtract, multiply, and divide. Here are the specifications for the calculator: The calculator has one “accumulator”, which holds the result of all prior calculations. The calculator is set to 0.0 when the calculator is turned on (i.e., instantiated). On the console, the user then enters an operator (+, -, *, or /) and a number. Your console will then apply the operator and operand to the number in the accumulator, and...
Calculator Class Instructions Create a calculator class that will add, subtract, multiply, and divide two numbers....
Calculator Class Instructions Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. The class must check for a correct operator (+,*,-,/), and a number (integer) for the second and third argument entered. The calculator cannot divide by zero...
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
Make a python calculator which deals with arithmetic include plus, minus, divide, and multiply as well...
Make a python calculator which deals with arithmetic include plus, minus, divide, and multiply as well as explaining each answer and use if statement using sign operator.
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
C++ For this assignment, you will write a C++ program to either add (A), subtract (S),...
C++ For this assignment, you will write a C++ program to either add (A), subtract (S), multiply (M), and (N), or (O) two matrices if possible. You will read in the dimensions (rows, then columns) of the first matrix, then read the first matrix, then the dimensions (rows then columns) of the second matrix, then the second matrix, then a character (A, S, M, N, O) to determine which operation they want to do. The program will then perform the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT