Friday, March 4, 2011

User-Defined Functions

Write a function that receives a floating point value x and returns it as a value rounded to two nearest decimal places. For example, the value 123.4567 will be rounded to 123.46 (Hint : Seek help of one of the math functions available in math libraray).

#include <stdio.h>
void roundoff(float num);
void main()
{
float num;
clrscr();
printf("Enter a floating point number to round of that value:");
scanf("%f",&num);
roundoff(num);
getch();
}
void roundoff(float num)
{
printf("Rounded number is: %5.2f",num);
}

OUTPUT
Enter a floating point number to round of that value : 123.4567
Rounded number is : 123.46

No comments:

Post a Comment