Answer to Question #250744 in C++ for Gayatri

Question #250744
There was a Grocery shop. Shopkeeper would like to keep transactions as simple as he can. Here he used to take money as whole number. To optimize transactions, he decided if someone buys Ogroceries from his shop, he will round money to the nearest whole number having zero as last digit. Write a program to help Shopkeeper to make transactions much simple.



Program

Constraints: 1<N<1000000

Example 1: Input:

7659

-Positive loteger

Output:

7660 -result-Integer rounding to nearest whole number having zero

as last digit.

Explanation: Given integer 7659" which is near to 7660, the whole number having zero as last digit, Hence output is 7660.

Example 2:

Input:

50

Positive integer
1
Expert's answer
2021-10-13T20:38:46-0400

Source code

#include <iostream>


using namespace std;


int round_Num(int num)
{
    int x = (num / 10) * 10;
    int y = x + 10;
    return (num - x > y - num)? y : x;
}
 


int main()
{
    int num;
    cout<<"\nEnter a number (between 1 and 1000000) : ";
    cin>>num;
    cout << round_Num(num) << endl;
    return 0;
}


Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS