Initial value of j is 1 and the last condition of the while statement is j=225. so the loop get executed 225 times. It does not change according to declaration.
Vivek Kkumar said:
(Wed, Apr 6, 2011 08:05:01 AM)
I could not understand.
(Tue, Jun 7, 2011 09:23:12 AM)
Hi vivek in the program the initital value of j=1 the statement in the while condition will execute until j value will become 255. so the statement will execute 255 times
(Sat, Jul 2, 2011 12:22:11 AM)
Thnks to all. Karthi please chek your values in this discussion.
(Fri, Jul 29, 2011 08:41:19 PM)
Loop will execute from j=0 to 224 at j=225 loop will terminated so it will execute upto 225 times from 0 to 224.
I think it makes it more clear.
(Mon, Aug 8, 2011 11:44:01 PM)
The body of the while loop will execute 255 times. But the while condition will execte one more time to became condition false.
It takes 256.
(Mon, Sep 5, 2011 11:25:49 PM)
you are right but see they didn't say while statement, they said while loop, so you ought consider the whole loop statements.
(Mon, Sep 12, 2011 09:13:30 AM)
In printf, why there are using %c. I can't understand please explain..
(Mon, Sep 12, 2011 05:10:44 PM)
I can't understand using of %c please explain.
(Tue, Oct 4, 2011 01:43:46 PM)
%c %d means short integer, according to this concept it won't affect while.
Hence while loop get executed by 255 times...understand.
(Tue, Oct 11, 2011 11:00:18 AM)
(Fri, Oct 14, 2011 01:09:26 AM)
Its answer is wrong because character is 127 to -128 so after going to 127 next j++ will take it to -128 so ..loop continues...
(Wed, Oct 26, 2011 03:57:12 PM)
I coudnt undrstand "%c %d". and also this "j,j" . why two js are used ? have anyone checked output using compiler?
(Wed, Dec 7, 2011 05:57:09 AM)
Thank you for discussion saswati and navana.
(Wed, Dec 7, 2011 05:59:50 AM)
%c is used to read character variable means 'g' or 'h' etc
wheare as %d is used to read integer example 22 44 etc
i checked it
(Thu, Dec 8, 2011 11:22:01 PM)
I think the answer is infinite. Loop continues because in case of characters after 127 next value will be -128. Hence the loop will never come to an end.
(Thu, Dec 15, 2011 09:33:21 PM)
In printing statement we have %c to print the j. as u told -128 to +127 ,but the given value is 255. But it is beyond the character limit. So whether here wrap around process will take place here can pls any one explain me clearly..
(Wed, Dec 28, 2011 01:45:58 PM)
Thank you for swathi and karthi.
(Thu, Jan 5, 2012 08:27:15 PM)
Thank you swathi.
(Mon, Jan 16, 2012 12:26:16 PM)
The answer is 256 its not 255 because the while loop gets executed when j=255.that is it takes 255 loop.but the while condition is executed untill the condition is failed.
So it fails when j=256.
Satya Vaag said:
(Thu, Jan 19, 2012 03:57:32 PM)
THANKS TO ALL
(Wed, Feb 1, 2012 03:40:21 PM)
Thank you karthi.
(Wed, Feb 15, 2012 01:46:36 PM)
It is in case of <= increment by 0ne of right side of the condition and then decrement it by left value;
(Tue, Mar 27, 2012 12:57:55 PM)
Hi, please have a look on the following program , I guess it is very easy.
while(j <= 225)
//printf("%c %d\n", j, j);
The count value will be 225.
(Thu, May 31, 2012 07:02:07 AM)
This program prints the ASCII characters from 1 to 255 and their respective number. That is why there is a "%c %d" in the printf, one for the char representation of whatever number 'j' is and the number itself.
What happens if in the above question 'short int' is replaced by 'long int' ? Please help.
(Sun, Aug 26, 2012 10:05:52 AM)
When this is short int. It again wrap around to zero so definitly infinite loop.
(Fri, Aug 31, 2012 04:21:09 PM)
Sangeetha,the range of short signed int is from -32768 to +32767.So,it won't wrap around.You are confusing it with char whose range is from -128 to +127.
(Fri, Sep 7, 2012 05:41:32 PM)
If int is not mentioned signed or unsigned then we take default signed.here we are showing character too so it will execute upto +127 then it goes to -127,-126.....,0,1,.....127 that mean it will execute infinite times.
(Mon, Sep 10, 2012 02:32:00 PM)
We are using character only in printf statement. not in condition. in while(j<=255) j is an integer variable. So in printf statemnt for %c it will print from 1,2.....127,-128,-127.....0 so exactly after 255 times of the execution of the loop. The condition fail and loop will be terminated.
(Wed, Oct 24, 2012 11:12:31 AM)
J=1 and while (j <= 255).
J start from 1 to 255 and run only 255 times, it goes to 255 because of <= if this sign is only < then it goes to only 1 to 254 and run only 254 times.
(Fri, Apr 5, 2013 07:02:35 PM)
float num = 23.34;
sprintf(result, "%f", num);
printf("\n The string for the num is %s", result);
This program shows an error output too large. Can anyone tell me why this error is occuring?
Vishal Naik said:
(Fri, May 10, 2013 07:43:46 PM)
Do it manually for a shorter number, ex while(j <= 3), you will get the answer as 3. Similarly when while(j <= 255), Answer is 255.