Question

In: Computer Science

Write a program to reverse each integer number on array (size 3) using while loop. C++...

Write a program to reverse each integer number on array (size 3) using while loop. C++
Input: 3678 2390 1783
Output: 8763 0932 3871

Solutions

Expert Solution

#include <iostream>
#include <sstream> // for string streams
#include <string>

using namespace std;

int main()
{   long a[]={3678, 2390, 1783};
    long n, reversedNumber, remainder;
   for (int i=0;i<=2;i++)
   {   n=a[i];
       reversedNumber = 1;
       while(n > 0)
       {
        remainder = n%10;
        reversedNumber = reversedNumber*10 + remainder;
        n /= 10;
        }
      
    ostringstream str1; // declaring output string stream

    // Sending a number as a stream into output
    // string
    str1 << reversedNumber;

    // the str() coverts number into string
    string r = str1.str();
     cout << "Reversed Number = " << r.substr(1)<<endl;
    }


    return 0;
}

OUTPUT:

Reversed Number=8763

Reversed Number=0932

Reversed Number=3871


Related Solutions

Multiples of 2 and 3: write a c++ program Using a while loop, write a program...
Multiples of 2 and 3: write a c++ program Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below.
1 for each of the problems listed below write the c++ program while using WHILE loop...
1 for each of the problems listed below write the c++ program while using WHILE loop structures A program will display each term in the following sequence 1 -10 100 -1000 10000 -100000 1000000 A program will calculate and display the corresponding celsius temperatures for the given Farenheit ones from 0f to 212 f (hint c=(f-32/1.8)
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
Using C language: Write a program that asks the user for the size of an array,...
Using C language: Write a program that asks the user for the size of an array, then reads a number of integer values (from user input) into the array. Write a function to print out the array and call it to print the array out after all values are read in. Write a function to implement Insertion Sort and run it on the data array to sort the array. Write another function to implement Selection Sort and run it on...
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size...
C++ 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write C++ program to do the following: 1. Create integer array size of 10 2. Ask...
Write C++ program to do the following: 1. Create integer array size of 10 2. Ask user input the values of the array's element using for loop 3. pass the array to void function. in void function do the following: a. Find the maximum of the array. b. Compute the element average c. Find out how many numbers are above the average d. Find out and print how many numbers are below the average e. find out how many numbers...
In C++ Write a function that took in SIZE and array [size] and counted the number...
In C++ Write a function that took in SIZE and array [size] and counted the number of elements >100
A)Write a C++ program using a while loop for Programming Exercise 5.1 on p. 193. Turn...
A)Write a C++ program using a while loop for Programming Exercise 5.1 on p. 193. Turn in a printout of the program and a printout of the results. Test the program for the two test cases in the book along with a third test case that includes 10 valid numbers (including some negative and some positive).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT