"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, March 2, 2010

Write a complete C++ program to do the following

(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.)


#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();


}

1 comment:

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.