Friday, March 4, 2011

User-Defined Functions

Write a function that will round a floating-point number to an indicated decimal place. For example the number 17.457 would yield the value 17.46 when it rounded off to two decimal places.

#include <stdio.h>
void Round_off(float x);
void main()
{
float x;
clrscr();
printf("Enter a floating point number:");
scanf("%f",&x);
Round_off(x);
getch();
}
void Round_off(float x)
{
int y;
printf("Enter the decimal places to round off the number:");
scanf("%d",&y);
printf("Rounded off number: %5.*f",y,x);
}

No comments:

Post a Comment