int n ; n = 3 ; if (n != 3) { printf("Captain Fantastic\n") ; } else if (n * 2 <= 5 + n) { printf("Brown Dirt Cowboy\n") ; } else { printf("Rocket Man\n") ; }
int i; for (i = 0 ; i < 9 ; i = i + 2) { printf("%d\n", 2 * i) ; }
int n, m ; n = 1 ; m = 1 ; while (n < 30) { printf ("n = %d, m = %d\n", n, m) ; m = m + 2 ; n = n + m ; }
int a = 1, b = 2 ; printf("a = %d, b = %d\n", a, b) ; a += b ; printf("a = %d, b = %d\n", a, b) ; a = b++ ; printf("a = %d, b = %d\n", a, b) ;
int a, b ; a = 6 ; b = 9 ; if ( a * b == 42 ) { printf("Hitchhiker's Guide\n") ; } else if ( a - b < -3 ) { printf("Milliway's\n") ; } else { printf("Life, the Universe and Everything\n") ; }
int n, i ; i = 0 ; n = 2048 ; while (n > 0) { n = n / 2 ; printf("n = %d\n", n) ; i++ ; } printf ("i = %d, n = %d\n", i, n) ;
2 + 7 + 6 * 4 - 5 / 2 + 8 % 3
int a, b ; a = 6 ; b = a + 7 ; printf("a = %d, b = %d\n", a, b) ; a += b / 3 ; printf("a = %d, b = %d\n", a, b) ; a = b = 2 * a ; printf("a = %d, b = %d\n", a, b) ;
int a ; a = 27 ; if ( a > 27 ) { printf("Georges Seurat\n") ; } else if ( a % 3 == 0) { printf("Edvard Munch\n") ; } else { printf("Joan Miro\n") ; }
int a, b; a = 11; b = 27; a++; a += b; b = a - b; a -= b; printf("a is %d and b is %d\n", a, b);
int i, j, k; i = j = 0; k = 3; while ( (i+j) < k) { i++; j++; k++; printf("End of pass %d: j=%d and k=%d\n",i,j,k); }
#define pi 3.1416 int a; double b; float c; b = a = pi*2.0; c = (int) pi + a printf("a is %d b is %f c is %f\n,a,b,c);
int a, b; c; a = b = c = 2; a *= (b *= (c *= 2)); printf("a is %d, b is %d, and c is %d\n", a, b, c);
BOOL p, q, r, s; p = TRUE; q = FALSE; p_and_q = (p && q); p_or_q = (p || q); if (p_and_q) printf("Great!\n"); if (p_or_q) printf("Good!\n");
int i; while(i<5) { if(i=2) { printf("Hello \n"); } else { printf("Hello World \n"); } i++; }
int num, i= 1, count =0; num = GetInteger(); while(num/i != 0) { i = i*10; count ++; } printf("count = %d \n", count);
Assume you are the user entering the value for num. what does count end up calculating?
int i = 0; if(i = 1) { printf ("Pink Floyd"); } else if (i == 2) { printf ("Led Zeppelin"); } else { printf ("Grateful Dead"); }
int p = 0; if (p) { printf("ADIOS \n"); } else { printf("ALOHA \n"); }
int p = 4; float q = 10.0; int result; while (p > 0) { result = q / p; printf("%d \n", result); p -- ; }