u

Thursday 7 June 2012

C++ Program to accept a number x. Count number of digits in x and store it in n, form y that has the number of digits n at ten's place and the most significant digit of x at one's place. Display y. sample input: x= 16833, y = 51, since no.of digits of x is 5 and 1 is the msd of x

C++ Program to accept a number x. Count number of digits in x and store it in n, form y that has the number of digits n at ten's place and the most significant digit of x at one's place. Display y. sample input: x= 16833, y = 51, since no.of digits of x is 5 and 1 is the msd of x


 #include<conio.h>
#include<iostream.h>
main()
{
clrscr();
int x,y,z,i,n=0,num, msd, digit;
cout<<"Enter any number as x"<<endl;
cin>>x;
// computing number of digits.
num=x;
while(num>0)
{
digit=num%10;
n=n+1;
num=num/10;
}
msd=digit;
y=n*10+msd;
cout<<"The value of Y is "<<y;
getch();
return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More