1. Write a program that consists of 3 functions, each of which is stored in a separate source file. The function increment accepts an integer parameter whose return value is the value of the parameter plus the 1.increment function should be located in the file increment.c. The second function, called Negate, also accepts a shaping parameter whose return value is the negative of the parameter. The last function is main, which is stored in the file main.c, which calls the other two functions separately with the parameter 10,0,-10 and prints the error.
int increment (int n) {return n+1;} int negate (int n) {return-n;} int main () {printf ("%d\n", Increment (10)); printf ("%d\n", Increment (0)); printf ("%d\n", Increment (-10)); printf ("%d\n", negate (10)); printf ("%d\n", negate (0)); printf ("%d\n", negate (-10)); System ("pause"); return 0;}
2. Write a program that reads the C source code from the standard input and verifies that all curly braces are correctly paired. Note: You do not have to worry about curly braces inside the comment, inside the string constant, or in the form of a character constant.
Int main () { int i = 0; char str[1000] = { 0 }; int count = 0; printf ("Please enter: \ n");     SCANF ("%s", str); while (Str[i] != ' \ n ') { if (str[i] == ' {') { count++; } if ( str[i] == '} ') && (count==0) { count--; break; } if ((str[i) == '} ') && (count != 0)) { count--; } i++; } if (count == 0) { printf ("All curly braces appear in pairs \ \"); } else { printf ("Curly braces do not appear in pairs \ \"); } system ("pause"); return 0;}
This article is from the "Sean" blog, so be sure to keep this source http://seann.blog.51cto.com/11126490/1740206
C and Pointers chapter two programming exercises