C Language

May 23, 2023

How to use floating arithmetic operator in c language

program to use floating arithmetic operator 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

  1. Declare float three variable a , b and s
  2. Initialize in float variable a=12.4 b=3.8
  3. Assign S variable with sum of variable a and b
  4. printf inbuild function display S variable with decimal placeholder %d
  5. Assign S variable with difference of variable a and b
  6. printf inbuild function display S variable with decimal placeholder %d
  7. Assign S variable with product of variable a and b
  8. printf inbuild function display S variable with decimal placeholder %d
  9. Assign S variable with a/b of variable a and b
  10. printf inbuild function display S variable with decimal placeholder %d

by : Ajaj Khan

Quick Summary:

floating arithmetic operator in c language