#include <stdio.h> /* Global Variables */ int a = 2, b = 4, c = 8 ; int foobar(int b) { int a ; a = b + c ; b = 2 * a ; c = b + 1 ; ; printf("foobar: a = %d, b = %d, c = %d\n", a, b, c) ; return(b) ; } main() { a = foobar(c) ; printf("main: a = %d, b = %d, c = %d\n", a, b, c) ; }
Click here for a sample answer.
int i, j; for (i = 0; i <= 2; i++) { for (j = 0; j <= 2; j++) { if ( i * i < j ) printf("X") ; else printf("O") ; } printf("\n") ; }
Click here for a sample answer.
int f(int x, int *p, int *t) { x = x + 1 ; *p = 2 * *p ; *t = 3 * *t ; x = x + *p + *t ; return(x) ; } main() { int a = 1, b = 2, c = 3 ; a = f(a, &b, &c) ; printf("First Call: a = %d, b = %d, c = %d\n", a, b, c) ; c = f(a, &b, &b) ; printf("Second Call: a = %d, b = %d, c = %d\n", a, b, c) ; }
Click here for a sample answer.
#include <stdio.h> #include "genlib.h" #include "simpio.h" #include "strlib.h" main() { int i, start, stop ; string str ; str = "Our zip code is 21228." ; for (i = 0 ; str[i] != '\0' ; i++) { if ( str[i] > 'w' ) break ; } start = i ; for (i = start ; str[i] != '\0' ; i++) { if ( str[i] >='0' && str[i] <= '9' ) break ; } stop = i ; printf("%s\n", SubString(str, start, stop) ) ; }
Click here for a sample answer.
4 8 16 32 64 128
Click here for a sample answer.
string str ; int i ; i = 0 ; str = GetLine() ; while ( str[i] != '\0' ) { if (str[i] == 'a') break ; i = i + 1 ; } printf ("Answer: %d\n", i) ;
Click here for a sample answer.
Click here for a sample answer.