English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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;
}

2007-01-02 03:20:19 · 2 answers · asked by simran m 1 in Computers & Internet Programming & Design

2 answers

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?

2007-01-02 03:35:54 · answer #1 · answered by I don't think so 5 · 0 0

What don't you get? In the example, 16833, the most significant digit is 1, and there are 5 digits, so y = 51. For x = 3842, y = 43. Don't you understand the implementation, or what?

2007-01-02 11:34:18 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers