Program to find Addition, Subtract, Multiplication, Division and Remainder of 2 numbers in C
Program:
#include<stdio.h>
int main()
{
int num1, num2, sum, sub, mult, remainder;
float div;
float div;
printf("Enter 1st number: ");
scanf("%d",&num1);
printf("Enter 2nd number: ");
scanf("%d",&num2);
sum=num1+num2;
printf("Sum is: %d",sum);
sub=num1-num2;
printf("Subtraction is: %d",sub);
mult=num1*num2;
printf("Multiplication is: %d",mult);
div=(float)num1/num2;
printf("Division is: %f",div);
remainder=num1%num2;
printf("Remainder is: %d",remainder);
return 0;
return 0;
}
Output:
Note:
We have used float for division since if we use div variable of int type answer we will get will be of int type.
e.g: If we use div variable of int type then 25/3 will give answer as 8 and not 8.333333
Summary:
Output:
Note:
We have used float for division since if we use div variable of int type answer we will get will be of int type.
e.g: If we use div variable of int type then 25/3 will give answer as 8 and not 8.333333
Summary:
+ is used for addition.
- is used for subtraction.
* is used for multiplication.
/ is used for division.
% is used to find remainder.
- is used for subtraction.
* is used for multiplication.
/ is used for division.
% is used to find remainder.
No comments:
Post a Comment