Professional Documents
Culture Documents
A2
A2
A2
h>
#include<iostream.h>
#include<math.h>
//using namespace std;
float num;
float roundToInteger(float x)
{
return floor( x + .5);
}
float roundToTenths(float x)
{
x /=10;
return floor(x + 0.5) * 10;
}
float roundToHundredths(float x){
x /=100;
return floor(x + 0.5) * 100;
}
float roundToThousandths(float x)
{
x /=1000;
return floor(x + 0.5) * 1000;
}
main(){
cout<<"enter a number: ";
cin>>num;
cout<<"\nroundToInteger: " << roundToInteger(num)<<endl;
cout<<"\nroundToTenths: " << roundToTenths(num)<<endl;
cout<<"\nroundToHundredths: " << roundToHundredths(num)<<endl;
cout<<"\nroundToThounsandths: " << roundToThousandths(num)<<end
l;
}