How to use floating arithmetic operator in c language
Floating Arithmetic Operator
On this page
Floating Arithmetic Operator
Program to us Size of Operator in C Language
#include<stdio.h>
int main()
{
float a = 12.4, b = 3.8, s;
s = a + b;
printf("sum = %.2f\n",s);
s = a - b;
printf("difference = %.2f\n",s);
s = a * b;
printf("product = %.2f\n",s);
s = a/b;
printf("a/b=%.2f\n",s);
return 0;
}
Output
sum = 16.20
difference = 8.60
product = 47.12
a/b = 3.26
Steps Description
- Declare float three variable a, b and s
- Initialize in float variable a = 12.4 b = 3.8
- Assign S variable with sum of variable a and b
- printf inbuild function display S variable with decimal placeholder %d
- Assign S variable with difference of variable a and b
- printf inbuild function display S variable with decimal placeholder %d
- Assign S variable with product of variable a and b
- printf inbuild function display S variable with decimal placeholder %d
- Assign S variable with a/b of variable a and b
- printf inbuild function display S variable with decimal placeholder %d