C 8 ( ) C 1 / 30
n! a n+2 = a n+1 + a n ( ) C 2 / 30
#include <stdioh> struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a, b; struct student c={"frank", 90; ( ) C 3 / 30
#include <stdioh> #include <stringh> /*strcpy */ struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a, b; strcpy(aname,"frank"); amath = 90; aphys = 83; ( ) C 4 / 30
= #include <stdioh> #include <stringh> /*strcpy */ struct student{ char name[20]; int math; int phys; ; int main(void){ b=a; return 0; Name:%sY=n",bname); Math:%dY=n",bmath); Physics:%dY=n",bphys); struct student a,b; strcpy(aname, "Frank"); amath = 90; aphys = 83; Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); Name:Frank Math:90 Physics:83 Name:Frank Math:90 Physics:83 ( ) C 5 / 30
struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a, *pa; aname amath aphys ( ) C 6 / 30
(&) struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a, *pa; pa = &a; pa aname amath aphys ( ) C 6 / 30
(->) -> (* ) #include <stdioh> #include <stringh> struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a,*pa; strcpy(aname, "Frank"); amath = 90; aphys = 83; pa=&a; strcpy(pa->name, "Thomas"); pa->phys = 92; return 0; Name:%sY=n",pa->name); Math:%dY=n",pa->math); Physics:%dY=n",pa->phys); Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); ( ) C 7 / 30
(->) -> (* ) #include <stdioh> #include <stringh> struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a,*pa; strcpy(aname, "Frank"); amath = 90; aphys = 83; Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); pa=&a; strcpy(pa->name, "Thomas"); pa->phys = 92; return 0; Name:Frank Math:90 Physics:83 Name:Thomas Math:90 Physics:92 Name:%sY=n",pa->name); Math:%dY=n",pa->math); Physics:%dY=n",pa->phys); ( ) C 7 / 30
#include <stdioh> #include <stringh> struct student{ char name[20]; int math; int phys; ; int main(void){ struct student a,*pa; strcpy(aname, "Frank"); amath = 90; aphys = 83; return 0; Name:%sY=n",pa->name); Math:%dY=n",pa->math); Physics:%dY=n",pa->phys); Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); pa=&a; strcpy(pa->name, "Thomas"); pa->phys = 92; ( ) C 8 / 30
#include <stdioh> #include <stringh> struct student{ char name[20]; int math; int phys; ; int main(void){ return 0; Name:%sY=n",pa->name); Math:%dY=n",pa->math); Physics:%dY=n",pa->phys); Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); struct student a,*pa; strcpy(aname, "Frank"); amath = 90; aphys = 83; Name:%sY=n",aname); Math:%dY=n",amath); Physics:%dY=n",aphys); pa=&a; strcpy(pa->name, "Thomas"); pa->phys = 92; Name:Frank Math:90 Physics:83 Name:Thomas Math:90 Physics:92 Name:Thomas Math:90 Physics:92 ( ) C 8 / 30
#include <stdioh> struct student{ /**/ int main(void){ struct student S1 = {"Frank",90,83; ; char name[20]; int math; int phys; double ave; Average(&S1); Name =%sy=n",s1name); Math =%dy=n",s1math); Phys =%dy=n",s1phys); Ave =%2fY=n",S1ave); void Average(struct student *std){ /* */ int sum; sum = std->math + std->phys; std->ave = (double) sum/2; return 0; Name =Frank Math =90 Phys =83 Ave =8650 ( ) C 9 / 30
Average struct student Average(struct student temp){ tempave = (double) (tempmath + tempphys)/2; return temp; int main(void){ S1=Average(S1); ( ) C 10 / 30
struct [ ]; struct student Std[20]; for(i=0;i<n;i++){ Std[i]ave = (double)(std[i]math+std[i]phys)/2; ( ) C 11 / 30
081c 20 20 100 119 N N*29+83)%100, (N*13+58)%100 20 void InputData(struct student *X) /*student */ 100 83 58 705 101 12 71 415 118 5 92 485 119 34 5 195 485 515 500 ( ) C 12 / 30
3 struct student Std[20]; Std struct student Std[N]; int i; for(i=0;i<n;i++){ Std[i]No = 100+i; InputDATA(&Std[i]); Std[i]ave = (Std[i]math+Std[i]phys)/20; ( ) C 13 / 30
3 struct student Std[20]; Std struct student Std[N]; int i; struct student Std[N], *p_std; int i; p_std = Std; for(i=0;i<n;i++){ Std[i]No = 100+i; InputDATA(&Std[i]); Std[i]ave = (Std[i]math+Std[i]phys)/20; for(i=0;i<n;i++){ p_std->no = 100+i; InputDATA(p_Std); p_std->ave = (p_std->math+p_std->phys)/20; p_std ++; ( ) C 13 / 30
struct student Std[N], *p_std; int i; p_std = Std; struct student Std[N], *p_std; int i; p_std = Std; for(i=0;i<n;i++){ p_std->no = 100+i; InputDATA(p_Std); p_std->ave = (p_std->math+p_std->phys)/20; p_std ++; for(i=0;i<n;i++){ (p_std+i)->no = 100+i; InputDATA(p_Std+i); (p_std+i)->ave = ((p_std+i)->math+(p_std+i)->phys)/20; ( ) C 14 / 30
( ) C 15 / 30
1! = 1 2! = 1! 2 3! = 2! 3 = (1! 2) 3 n! = (n 1)! n = (n 2)! (n 1) n = #include <stdioh> int factorial( int n ){ int m; if( n==0 n==1 ){ 1"); return 1; else{ %d *(",n); m = n * factorial( n-1 ); )"); return m; int main(void){ N= 5; factorial(n); return 0; ( ) C 16 / 30
2 f (0) = 0 f (1) = 1 f (2) = f (1) + f (0) = 1 f (3) = f (2) + f (1) = 2 f (n) = f (n 1) + f (n 2) int fibonacci( int n ){ if( n==0 ){ return 0; else if( n == 1){ return 1; else { return fibonacci(n-1)+fibonacci(n-2); ( ) C 17 / 30
( ) C 18 / 30
int factorial( int n ){ int m; if( n==0 n==1 ){ 1"); return 1; else{ %d *(",n); m = n * factorial( n-1 ); )"); return m; int factorial( int n ){ int i, m=1; 1"); for( i=2; i<=n; i++){ *%d",i ); m = m *i; return m; ( ) C 19 / 30
int fibonacci( int n ){ if( n==0 ){ return 0; else if( n == 1){ return 1; else { return fibonacci(n-1)+fibonacci(n-2); int fibonacci( int n ){ int i, fn, fn1=1, fn2=0; if( n==0 ){ return 0; else if( n == 1){ return 1; else { for( i=2; i<=n;i++){ fn=fn1+fn2; fn2=fn1; fn1=fn; return fn; ( ) C 20 / 30
:082c n r n C r combination n C r nc r = n 1 C r 1 + n 1 C r, n C 0 = n C n = 1, n C 1 = n Input n : 20 Input r : 3 20 C 3 = 1140 ( ) C 21 / 30
3 A C A B C A B C 2 n 1 ( ) C 22 / 30
( ) C 23 / 30
( ) C 23 / 30
3 0 A B C 4 A B C 1 A B C 5 A B C 2 A B C 6 A B C 3 A B C 7 A B C ( ) C 24 / 30
n n 1 A B A C n 1 3 1 A B A C 3 1 C ( ) C 25 / 30
n 1 A B B A C A B B B A A ( ) C 26 / 30
void Hanoi(int n, char *from, char *work, char *dest) from dest) n n from work dest ( ) C 27 / 30
main N (from) A (dest) C (work) B Hanoi(N,"A","B","C"); from dest Move a disk from %s to %s",from,dest); n 1 (from) (work) Hanoi(n-1,from, dest, work); ( ) C 28 / 30
: 083c How many disks? 3 Move the disc from A to C Move the disc from A to B Move the disc from C to B Move the disc from A to C Move the disc from B to A Move the disc from B to C Move the disc from A to C ( ) C 29 / 30
#include <stdioh> void Hanoi(int n,char *from,char *work,char *dest){ if(n>=2) Hanoi(,,, ); Move the disc from %s to %sy=n",from,dest); if(n>=2) Hanoi(,,, ); int main(void){ int N; How many disks? "); scanf("%d",&n); Hanoi(N,"A","B","C"); return 0; ( ) C 30 / 30