Off Topic-06.05.2010

Yesterday i did my exam and Shariar Manzoor was the maker of this question. Exam question was standard. There I found a program and that was given below:
#include
int main (void)
{
    int i;
    for(i=0;i<=100;i++)


    {
       if(i%9) continue;
       if(i%5==0)continue;
       printf("%d ",i);
    }
    system("pause");
    return 0;




What is the output of this program ?? Everyone found that. But that was not a right answer. I also found the wrong answer. Because I did not know if the condition is like this ( i%9 ) if i=0 and the range is 0 to 100 what will be the output and thats why i could not get the right answer. But after coming home I solve the program. Now I know i%2 or i%3 what is its meaning. If initial value of i is 0 and the nth value of i is 10 and the condition is i%2 then i will print the the odd number. Else the condition is i%3 then i will print the even number. When the condition is i%2 you use continue keyword then i will print even number and if the condition is like this (i%3)continue; i will print odd number.

0 comments:

Post a Comment