Question

I need to revise a c++ code that asks to: enter up to 5 digits positive...

I need to revise a c++ code that asks to: enter up to 5 digits positive integer number, then reverse the order of the digits. The program outputs both numbers and calculates their square roots in the following way

Please enter a 5-digits integer: ( inputs 56789) output as follow

The square root of 566789 is:
The number in reverse is: 98765
The square root of the reversed number 98765 is:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE FOR THE PROBLEM

1 #include<iostream>

2 #include<math.h> // for calculating square root

3 using namespace std;

4 int main()

5 {

6 int num;

7 cout<<"enter upto 5 digit integer "<<endl;

8 cin>>num; // taking input of number

9 int q=num,r; // storing number in q

10 int num2=0; // declaring num2 to store reverse of num

11 while(q!=0) // begin of while loop

12 {

13 r=q%10;

14 q=q/10;

15 num2=num2*10+r;

16 } // end of while loop

17 // sqrt is used to find square root.

18 cout<<"The square root of "<< num <<" is: "<<sqrt(num)<<endl;

19 cout<<"The number in reverse is: "<<num2<<endl;

20 cout<<"The square root of the reversed number "<< num2 <<" is: "<<sqrt(num2)<<endl;

21 }

22

23

24 /** while loop is used here to reverse the number , every time the number is

25 divided by 10 and the remainder is stored in num2 and the quotient becomes new

26 q so that the number can be reversed .**/

Screenshot is below

#include<iostream> #include<math.h> using namespace std; int main( { // for calculating square root int num; cout<<enter uptAtulsmacnet:~ atulverma$ g++ cai.cpp Atulsmacnet:~ atulverma$ /a.out enter upto 5 digit integer 56789 The square root of 5678

Add a comment
Know the answer?
Add Answer to:
I need to revise a c++ code that asks to: enter up to 5 digits positive...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to write this code in C++???? using fstream Write a program which: Asks the user...

    How to write this code in C++???? using fstream Write a program which: Asks the user to enter a positive integer greater than 0 Validates that the entry is a positive integer Outputs the digits in reverse order with a space separating the digits Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even) If there are no even digits, the an appropriate message should be displayed: There are no even...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647....

    C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Write a program that inputs two positive integers of, at most,...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • Program#3(17 points): write a java program (SunDigits) as follows The main method prompts the user to enter an integer number. The method then calls Method Sum (defined blew) to add the digits and re...

    Program#3(17 points): write a java program (SunDigits) as follows The main method prompts the user to enter an integer number. The method then calls Method Sum (defined blew) to add the digits and return their total. The main method then prints the digits total with proper label as shown below Method Sum )is of type integer and takes an integer value. The method recursively adds up the digits and returns their total. Document your code and use proper prompts for...

  • C++ Write a program that asks user to input three positive integers one at a time,...

    C++ Write a program that asks user to input three positive integers one at a time, then compute and output the largest entered number. Use if-else statements for three integer comparison and use for loops for a user validation. Example output: Enter an integer: -7 Invalid! Number must be positive. Enter an integer: -2 Invalid! Number must be positive. Enter an integer: 5 Enter an integer: 7 Enter an integer: 1 Largest number: 7

  • NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number...

    NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number ( the user should input any integer number, say N), then the program outputs N if N is even; or N+3 if N is odd ( note: the output is always even) Example: Enter any number: 25 Even output is: 28 Another example: Enter any number: 32 Even output is: 32.

  • MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is...

    MATLAB Question: TASK 5 12 MARKS -L06N] The rounded-square-root (RSR) of a positive integer n is defined as the square root of n rounded to the nearest integer. Adapting Heron's method to integer arithmetic allows the rounded-square-root of n to be calculated as follows. Let d be the number of digits of number n d-1 If d is odd, then Xo = 2 × 107- If d is even, then Xo-7 × 107- where xo is the starting guess for...

  • use c++ language, keep it simple i am using code block Exercise #2: Digitise a number...

    use c++ language, keep it simple i am using code block Exercise #2: Digitise a number Write the function digitiselint, int[]) of type int, which takes an integer N and finds all the digits of that integer and save them in an array. The function then returns the number of digits in N. Write the main() program that reads an integer, calls the function digitisel ), and prints the digits in reverse order. Sample input/output: Enter an integer: 2309456 The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT