How to write a C Program to Add, Multiply, Subtract and Divide in C Programming Language ?
Solution:
#include<stdio.h>
/*C Program to Add, Multiply, Subtract and Divide*/
int main()
{ int M1, M2, M3;
char c;
printf(" What do you want? Press +,-,* or /");
scanf("%c",&c);
if(c =='-')
{
scanf("%d%d",&M1,&M2);
M3 = M1-M2;
printf("%d",M3);
}
else
if (c =='+')
{
scanf("%d%d",&M1,&M2);
M3 = M1+M2;
printf("%d",M3);
}
else
if(c =='*')
{
scanf("%d%d",&M1,&M2);
M3 = M1*M2;
printf("%d",M3);
}
else
if(c =='/')
{
scanf("%d%d",&M1,&M2);
M3 = M1/M2;
printf("%d",M3);
}
else
{
printf("No task");
}
}
Solution:
#include<stdio.h>
/*C Program to Add, Multiply, Subtract and Divide*/
int main()
{ int M1, M2, M3;
char c;
printf(" What do you want? Press +,-,* or /");
scanf("%c",&c);
if(c =='-')
{
scanf("%d%d",&M1,&M2);
M3 = M1-M2;
printf("%d",M3);
}
else
if (c =='+')
{
scanf("%d%d",&M1,&M2);
M3 = M1+M2;
printf("%d",M3);
}
else
if(c =='*')
{
scanf("%d%d",&M1,&M2);
M3 = M1*M2;
printf("%d",M3);
}
else
if(c =='/')
{
scanf("%d%d",&M1,&M2);
M3 = M1/M2;
printf("%d",M3);
}
else
{
printf("No task");
}
}
Learn More :
Divide
Subtract
Add
- C Program To Add Digits Of Entered Number
- C Program To Add n Numbers
- C program to add first seven terms of the following series using a for loop: (1/1!) + (2/2!) + (3/3!) + .....
- C Program to Adds literal to list of literals
- C Program to Add-Subtract Series 5-10+15
- C Program to Add Series 1+3+5
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program that prompts the user to input a string, (whitespaces allowed)
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program