C Language

June 12, 2023

How to use floating point arithmetic operators in C language

Program to use floating point arithmetic operators in C language


#include <stdio.h>
int main()
{
    float a = 12.4, b = 3.8;
    printf("Sum=%.2f\n", a + b);
    printf("Difference=%.2f\n", a - b);
    printf("Proudct=%.2f\n", a * b);
    printf("a/b=%.2f\n", a / b);
    return 0;
}

Output


Sum=16.20
Difference=8.60
Proudct=47.12
a/b=3.26

Steps / Description

  1. Declare variable float a and b
  2. Initialize in float variable a = 10.4, b = 5.8
  3. printf inbuild function to display sum of variable a > and b with decimal place holder %f
  4. prinf inbuild function to display difference of variable a and b with decimal place holder %f
  5. printf inbuild function to display product of variable a and b with decimal place holder %f
  6. printf inbuild function to display a/ba and b with decimal place holder%f

by : Nadeem Khan

Quick Summary:

Floating Point