12345678910111213141516171819202122232425262728293031323334353637
#include <iostream> #include <conio.h> using namespace std ; int main() { long double num,decimal,temp; int rd,i; cout << "Enter the no. and rounding digit :"; cin>>num>>rd; i=rd; temp=(int)num; decimal=num-temp; while(i) { decimal*=10; i--; } decimal=(int)decimal; i=rd; while(i) { decimal*=0.1; i--; } num=(int)num+decimal; cout.setf(ios::fixed,ios::floatfield); cout<<"The rounded number is :"<<num; _getch(); return 0; }
cout.setf(ios::fixed,ios::floatfield);