You are not logged in. Please login at www.codechef.com to post your questions!

×

regarding while loop

{
int i;
while(i=10)
{
printf("%d",i);
i=i+1;
}
return 0;
}

//explain how o/p obtained //

asked 14 Mar '14, 22:54

pranay85kumar's gravatar image

0★pranay85kumar
-24
accept rate: 0%

edited 14 Mar '14, 23:03

betlista's gravatar image

3★betlista ♦♦
16.9k49115225


it will always print 10 because every time i becomes 11(i=i+1) and then it becomes 10(while(i=10)) and then 10 gets printed....if you do this:
while(i=10)
{
printf("%d ",i);
i=i+1;
printf("%d ",i);
}
output; 10 11 10 11 10........
and program will not terminate as while condition is always true(constant positive value of i)...

link

answered 14 Mar '14, 23:55

9_5_6_0_5_6_2_1_2_3's gravatar image

0★9_5_6_0_5_6_2_1_2_3
461
accept rate: 0%

I do not know exactly what are you asking, probably about infinite loop?

while(i=10) // this is always true, use == in C/C++
link

answered 14 Mar '14, 23:05

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

i mean while(i=10) true then printing 10 and then incrementing i=i+1 i.e now i=11 and then going back to while(i=10) here what happens whether i=11 or 10 but o/p is printing 10 infinitely please explain me this

(14 Mar '14, 23:14) pranay85kumar0★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,491
×42
×30
×19

question asked: 14 Mar '14, 22:54

question was seen: 748 times

last updated: 14 Mar '14, 23:55