(i) read an integer X.
(ii) form an integer Y by reversing the digits of X and integer S having sum of digits of X.
(iii) Output Y and S.
(For example , if X is equal to 5076, then Y should be 6705 and S should be 18.)
#include <iostream.h>
#include <conio.h>
void main()
{
int X, Y = 0, S = 0;
int r = 0;
cout<< "\n Enter an integer :";
cin >> X;
for(int i = X; i>0 ; i = i /10)
{
r = i % 10;
S = S + r;
Y = Y*10 + r;
}
cout << "\n The reverse of " << X << " is " << Y;
cout<< "\n The Sum of the digits = " << S;
getch();
}
(ii) form an integer Y by reversing the digits of X and integer S having sum of digits of X.
(iii) Output Y and S.
(For example , if X is equal to 5076, then Y should be 6705 and S should be 18.)
#include
#include
void main()
{
int X, Y = 0, S = 0;
int r = 0;
cout<< "\n Enter an integer :";
cin >> X;
for(int i = X; i>0 ; i = i /10)
{
r = i % 10;
S = S + r;
Y = Y*10 + r;
}
cout << "\n The reverse of " << X << " is " << Y;
cout<< "\n The Sum of the digits = " << S;
getch();
}
No comments:
Post a Comment