Round up a Decimal number in c++..

example Note = 3.5 is as 4
3.3 is as 3

Answers were Sorted based on User's Feedback



Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3..

Answer / vivek

#include <iostream>
#include <string>
using namespace std;


int main(void)
{
float a,b,c;
int k;
cout << "enter 1st number ";
cin>>a;
cout<<"enter 2nd number ";
cin>>b;
c=a/b;
cout<<"original value "<<c;
if (c=c+0.5)
{
k=c;
cout<<"\n"<<"round figure "<<k;
}
else
return 0;
}

Hope this code helped u smways

Is This Answer Correct ?    3 Yes 1 No

Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3..

Answer / vimala

void main()
{
float a,c;int b,d;
cout<<"ENTER ANY FLOAT VALUE:";
cin>>a;
b=a;c=(a-b);
if(c>=.5)
d=b+1;
else
d=b;
cout<<"AFTER ROUND UP THE DECIMAL NO IS:"<<d;
getch()
}

Is This Answer Correct ?    0 Yes 0 No

Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3..

Answer / pawarp

#include <iostream>
#include <cmath>
int main()
{
   float a;
   cout<<"Enter any float value to round up"<<endl;
   cin>>a;
   cout << round(a)<<endl;
   
   return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More OOPS Interview Questions

difine hierarchical inheritance.

9 Answers   ASD Lab, TCS,


class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash

0 Answers  


What is virtual Function.

1 Answers   Wipro,


#include <iostream> using namespace std; int main() { int a = 3; int c[5][5]; for (int x=0;x<5;x++) { for (int y=0;y<5;y++) { c[x][y] = x*y; } } cout << c[a][2]; }

1 Answers  


What are the advantanges of modularity

2 Answers  






What is the real time example of inheritance?

0 Answers  


1. Strong name 2. how to prevent a class from being inherited 3. delegates 4. default modifier for interface 5. default modifier for class 6. base class for exception 7. diff bet trigger and view in sql 8. how to exchange values from one page to another page 9. can multiple catch block ll be executed at same time 10. can u store different data types in an array & array list 11. when we ll use trigger 12. try,catch,finally usage

2 Answers  


What is the main feature of oop?

0 Answers  


Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.

0 Answers  


program for insertion ,deletion,sorting in double link list

0 Answers  


What is difference between oop and pop?

0 Answers  


what is function over loading?

5 Answers  


Categories