At this point, the basic knowledge of C language has been basically finished, but you will find that the C language, but you can not do anything, when I learned here is also the case, learning programming is a long process, the front is just the foundation of programming language, there will be a long way to go, and hope to continue.
Here, we do some small program practice, and then the large program is also assembled by small programs, as: No Kuibu, no, even thousands of miles.
To find the number of the Philippine-la-Fibonacci series:
# include <stdio.h>int main (void) {int N;long f1, f2, f3;int i;f1 = 1;F2 = 2;printf ("Please enter the required nth value: n ="); scanf ("%d", &A MP;N); if (n = = 1) {F3 = 1;} else if (n = = 2) {F3 = 2;} Else{for (i=3;i<=n;i++)//This is the program focus! {F3 = f1 + f2;f1 = F2;f2 = F3;}} printf ("The value of the nth item is:%ld\n", F3); return 0;}
spoof small virus program ~~! :
# include <stdio.h># include <windows.h># include <malloc.h>int main (void) {int c;int i;int J; Nihao: printf ("1: Shutdown \ n");p rintf ("2: Program exploded \ n");p rintf ("Please select:"); scanf ("%d", &c); if (c==1) {System ("shutdown-s-t "); The system function, called}else if (2==c) {printf ("You're too bad, I'm going to punish you!") \ n "); for (j=0;j<20; ++j) system (" Start ");} else {printf ("You knocked the wrong, please retype it!") \ n "); goto Nihao;} return 0;}
Determine if a number is prime (common):
# include <stdio.h>int main (void) {int val;int i;printf ("Please enter the number to be judged:"), scanf ("%d", &val); for (i=2; i<val; i+ +) {if (val%i = = 0) break;} if (i = = val) printf ("This number is prime!") \ n "); elseprintf (" This number is not prime! ") \ n "); return 0;}
The program that caused the memory panic:
# include <stdio.h># include <malloc.h>int main (void) {printf ("Haha! I will punish you ~ "); while (true) {int * p = (int *) malloc (1000); Unlimited request memory, memory full}return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Introduction to C programming--comprehensive exercises (i)