Arithmetic operations are addition, subtraction, multiplication ,division and modulus. All these operations can be performed in the C programming using arithmetic operators. Arithmetic operators are ( + , - , * , / ,%).Using these operators we can perform different types of operations.
Program To add two numbers.
Output :
In these program the first line "#include <stdio.h>" is the header file which is used for basic input and output in the program."int main()" here int is an return type which will return a integer value, "{" is the starting of the main function block. Then we take three variable as a,b,c which is of integer type, if you want decimal number replace "int" by "float". 'a' will store the first integer value, 'b' will store second integer value and 'c' will store the result of a + b. "printf" will display the message on the output screen and "scanf" will read the value given by the user. c=a+b is the operation to be performed and then printf will print the result on the output screen.
Similarly we can perform the operations like subtraction, multiplication, division, modulus in C as -
Program To subtract two numbers.
Output :
Program To add two numbers.
#include <stdio.h> int main() { int a,b,c; printf("Enter the value of a :"); scanf("%d",&a); printf("Enter the value of b :"); scanf("%d",&b); c=a+b; printf("Addition of a and b is %d.",c); return 0; }
Output :
Enter the value of a :5 Enter the value of b :2 Addition of a and b is 7.
In these program the first line "#include <stdio.h>" is the header file which is used for basic input and output in the program."int main()" here int is an return type which will return a integer value, "{" is the starting of the main function block. Then we take three variable as a,b,c which is of integer type, if you want decimal number replace "int" by "float". 'a' will store the first integer value, 'b' will store second integer value and 'c' will store the result of a + b. "printf" will display the message on the output screen and "scanf" will read the value given by the user. c=a+b is the operation to be performed and then printf will print the result on the output screen.
Similarly we can perform the operations like subtraction, multiplication, division, modulus in C as -
Program To subtract two numbers.
#include <stdio.h> int main() { int a,b,c; printf("Enter the value of a :"); scanf("%d",&a); printf("Enter the value of b :"); scanf("%d",&b); c=a-b; printf("Subtraction of a and b is %d.",c); return 0; }
Output :
Enter the value of a :8 Enter the value of b :4 Subtraction of a and b is 4.
Comments
Post a Comment