A2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <fstream.

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;
}

You might also like