# Recent questions tagged loop 1
for(int i=0; i<=100;i++) { if (i % 3 == 0) printf("Great); if(i%5 == 0) printf("India"); } Count the number of times GreatIndia is printed. 6 20 33 none of these
2
i have 1 doubt regarding the initialization of highlighted portion.Will the value of ’k’ change at each iteration or it will remain same (whatever value assigned to it during for loop initialization) ?
3
What is the return value of following function for 484? What does it to in general? bool fun(int n) { int sum = 0; for (int odd = 1; n > sum; odd = odd+2) sum = sum + odd; return (n == sum); } (A) False, it checks whether a given number is ... , it checks whether a given number is odd or not (D) True, it checks whether a given number is perfect square. Any one can explain output of above program?
4
#include <stdio.h> int main() { int i = 0; do { printf("Hello "); i = i++; } while (i < 5); return 0; } why this prints Hello infinitely? shouldn't it print Hello 5 times?
5
Consider the following program fragment: int d = 0; int i,j,k; for(i=1; i<31; ++i) for(j=1; j<31; ++j) for(k=1; k<31; ++k) if(((i+j+k)%3) == 0) d=d+1; printf("%d",d); The number of additions performed by the above program fragment is? a. 27,000 b. 27,000 x 3 c. 27,000 x 3 + 9,000 d. 9,930 + 2,700 x 3
6
What will be the output of following program:- Size of int is 4 bytes #incude<stdio.h> int main() { int a; for(a=1;a<=2147483647;a++) printf("%d\n",a); return 0; } a) will it print till its limit 2147483647 b) it will go to indefinate loop c) compile time error
7
for(i=0;i<=n;i++){ for(j=0;j<=i2;j++){ for(k=0;k<=$\frac{n}{2}$;k++){ x=y+z; }}} How many times the x=y+z statement will execute?
8
What is the output of this C code? #include<stdio.h> int main() { do printf("Inside while loop"); while(0); printf("After while loop"); } A) Infinite loop B) Compilation error C) After while loop D) Inside while loop After while loop
1 vote
9
#include <stdio.h> int main() { int a; int i=0,j=0; int res1=0,res2=0; int res={0}; for(i=0;i<10;i++) { a[i] = i+1; for(j=0;j<10;j++) { if(i!=j) res[j] = res[j] ^ a[i]; } } for(i=0;i<10;i++) { if(i&1) res2 = res2 ^ a[i]; else res1 = res1 ^ a[i]; } int sum=0; for(i=0;i<10;i++) sum += res1^res2^res[i]; printf("%d\n",sum); } Output of the above program ?
1 vote
10
Which one of the following sentences is true ? The body of a while loop is executed at least once. The body of a do … while loop is executed at least once. The body of a do … while loop is executed zero or more times. A for loop can never be used in place of a while loop.
1 vote
11
int i=0,j=0; if(i&&j++)printf (print I, j) printf(print I, j) output : is 0,0 My Question is.. ' if' statement is executed and failed as I and j have values 0,0 then why j is not incremented output has to be 0,1 according to my knowledge. Even ... get incremented after if loop. Why it is not happening? Ps: I'm not able to follow proper style in coding as I'm typing from mobile. Please excuse