C Program for Rounding off any Floating-point numbers

In stead of using round( ), roundf( ), ceil( ), floor( ) to round-off any numbers, this is the best manipulating way.

#include<stdio.h>
#include<conio.h>
void main()
{
  float i=6.8;
  int k;
  float r;
  k=i;
  r=((i-k)>=0.5)?k+1:k;
  printf("Rounding of %f is %f",i,r);
  getch();
}

OUTPUT:

No comments:

Post a Comment