(a) read an integer X.
(b) determine the number of digits n in X.
(c) form an integer Y that has the number of digits n at ten's place and the most significant digit of X at one's place.
(d) Output Y.
(For example , if X is equal to 2134, then Y should be 42 as there are 4 digits and the most significant number is 2.)
void main()
{
int X, Y = 0, n = 0;
int r = 0;
cout<< "\n Enter an integer :";
cin >> X;
for(int i = X; i>0 ; i = i /10)
{
r = i % 10;
n++;
}
Y = n * 10 + r;
cout << "\n The given number is " << X ;
cout<< "\n The new required number is = " << Y;
getch();
}
(b) determine the number of digits n in X.
(c) form an integer Y that has the number of digits n at ten's place and the most significant digit of X at one's place.
(d) Output Y.
(For example , if X is equal to 2134, then Y should be 42 as there are 4 digits and the most significant number is 2.)
#include <iostream.h>
#include <conio.h>
void main()
{
int X, Y = 0, n = 0;
int r = 0;
cout<< "\n Enter an integer :";
cin >> X;
for(int i = X; i>0 ; i = i /10)
{
r = i % 10;
n++;
}
Y = n * 10 + r;
cout << "\n The given number is " << X ;
cout<< "\n The new required number is = " << Y;
getch();
}
hello
ReplyDelete