Question

write a C program that works as the calculator which can operate with the four operations...

write a C program that works as the calculator which can operate with the four operations ( + - / * ) , the program should keep running and asks the user to end or continue use functions to create the calculator part ..

1- use if statements . with the upper operations

2- use functions to create the calculator part .

3- the program should keep running and asks the user to end or continue ..( use while statement )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<conio.h>
void add(int,int);
void subtract(int,int);
void divide(int,int);
void multiply(int,int);
void main()
{
int a,b,opt,ch;
printf("CALCULATOR");
printf("\n1.ADDITION");
printf("\n2.SUBTRACTION");
printf("\n3.DIVISION");
printf("\n4.MULTIPLICATION\n");
while(1)
{
printf("Enter first integer number:");
scanf("%d",&a);
printf("\nEnter second integer number:");
scanf("%d",&b);
printf("\nPlease Enter choice of Operation");
scanf("%d",&opt);
if(opt==1)
{
add(a,b);
}
else if(opt==2)
{
subtract(a,b);
}
else if(opt==3)
{
divide(a,b);
}
else if(opt==4)
{
multiply(a,b);
}
else
{
printf("Wrong choice\n");
}
printf("\nWant to continue (1/0):");
scanf("%d",&ch);
if(ch==0)
{
exit(0);
}
}
getch();
}
void add(int a,int b)
{
printf("%d",a+b);
}
void subtract(int a,int b)
{
printf("%d",a-b);

}
void divide(int a,int b)
{
if(b==0)
{
printf("Wrong value entered");
}
else
{
printf("%d",a/b);
}
}
void multiply(int a,int b)
{
printf("%d",a*b);
}


THE OUTPUT RUNS FINE AND OUTPUT HAS BEEN VERIFIED

Add a comment
Know the answer?
Add Answer to:
write a C program that works as the calculator which can operate with the four operations...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT