x is an integer x(2648).print the value of y of the above is
Answers
Output: 8462
Program in C++
#include<iostream>
using namespace std;
int main()
{
int x;
cout<<"Enter a number : ";
cin>>x;
int y = 0;
do
{
y = (y * 10) + (x % 10);
x = x / 10;
}
while(x != 0);
cout<<y;
return 0;
}
Explanation:
Initially y = 0
Initially x = 2648
x y = (y * 10) + (x % 10) x = x / 10
2648 y = (0 * 10) + (2648 % 10) x = 2648 / 10
y = 0 + 8 x = 264
y = 8
264 y = (8 * 10) + (264 % 10) x = 264 / 10
y = 80 + 4 x = 26
y = 84
84 y = (84 * 10) + (26 % 10) x = 26 / 10
y = 840 + 6 x = 2
y = 846
2 y = (846 * 10) + (2 % 10) x = 2 / 10
y = 8460 + 2 x = 0
y = 8462
0
So, final value of y = 8462