C program to perform addition, subtraction, multiplication and division
C program to perform basic arithmetic operations i.e. add , subtract, multiply and divide two numbers. Numbers are assumed to be integers and will be entered by the user.
Arithmetic operations.
Output:
C programming code
#include<stdio.h> main() { int first, second, add, subtract, multiply; float divide; printf("Enter two integers\n"); scanf("%d%d",&first,&second); add = first + second; subtract = first - second; multiply = first * second; divide = first / (float)second; //typecasting printf("Sum = %d\n",add); printf("Difference = %d\n",subtract); printf("Multiplication = %d\n",multiply); printf("Division = %.2f\n",divide); return 0; }
Arithmetic operations.
Output:
Comments
#1 Guest : superb
#2 Guest : but what if the user enters integers in the order 5 and 10?
#3 adminPs : Use long data type
Declare variable as
long var;
and use %ld as conversion specifier.
#4 Guest : hi
#5 Guest : multiplication
#6 adminPs : c program to multiply numbers without using multiplication sign