Store Display Sample

Store Display Sample


Store Display Sample
programming help!!!!!!!?

i don’t understand what is this program doing inspite of the explaination given. can you plz explain it in more and more detail such that i can understand?
content=// 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
#include
main()
{
clrscr();
int x,y,z,i,n=0,num, msd, digit;
cout<<"Enter any number as x"< 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 "< getch();
return 0;
}

The program takes a sequence of numbers and counts them. It then displays this count. Then, it takes the first digit given, and displays that.
So, 16833 is 5 digits long, and the first digit is a 1, so it outputs 51.
If you entered 1234567 it would say 71 since it is 7 digits long, and the first digit is a 1.
If you said 52 it would say 25, since it is 2 digits long, and the first digit is a 5.

Does this help? Or are you having trouble understanding how the program does what it does?

Post a Comment

Your email is never shared. Required fields are marked *

*
*