100 cases of classic C procedures == 71--80

xiaoxiao2021-03-06  45

[Program 71] Title: Write the input () and output () function input, output 5 student's data records. 1. Program analysis: 2. Source code: #define n 5struct student {char Num [6]; char name [8]; int score [4];} stu [n]; input (stu) Struct Stud Station Stu [] ; {INT I, J; For (i = 0; i

1. Program analysis: 2. Program source code: / * Creat a list * / # include "stdlib.h" #include "stdio.h" struct list {int data; structure; struct list * next;}; typef struct List Node; Typedef node * link; void main () {link PTR, Head; Int Num, i; ptr = (link) malloc (sizeof (node)); PTR = head; Printf ("please input 5 numbers ==> / n" ); for (i = 0; i <= 4; i ) {scanf ("% D", & num); PTR-> DATA = NUM; PTR-> Next = (link) malloc (sizeof (node)); if (i == 4) PTR-> Next = null; else ptr = ptr-> next;} Ptr = head; while (ptr! = null) {printf ("the value is ==>% d / n", Ptr -> data); PTR = Ptr-> Next;}} ==================================== ========================== 【Program 73】 Title: Reverse output a linked list.

1. Program analysis: 2. Source code: / * Reverse output a list * / # include "stdlib.h" #include "stdio.h" struct list * next;}; typedef struct List Node TYPEDEF NODE * LINK; Void Main () {Link PTR, Head, Tail; Int Num, I; Tail = (LINK) Malloc (SizeOf (Node)); Tail-> Next = Null; PTR = Tail; Printf (" / NPLEASE INPUT 5 DATA ==> / N "); for (i = 0; i <= 4; i ) {scanf ("% d ", & num); ptr-> data = Num; head = (link) malloc (SIDEOF (Node); ptr = head;} ​​ptr = ptr-> next; while (ptr! = null) {printf ("The value is ==>% d / n", Ptr -> data); PTR = Ptr-> Next;}} ==================================== ========================== 【Program 74】 Title: Connect two linked lists.

1. Program analysis: 2. Source code: #include "stdlib.h" #include "stdio.h" struct list {int data; struct list * next;}; type; typef node * link; link delete_node (LINK POINTER, LINK TMP) {IF (TMP == NULL) / * Delete first node * / return Pointer-> Next; else {if (tmp-> next-> next == null) / * delete last node * / TMP-> Next = NULL; Else / * delete the} = tmp-> next-> next; return pointer;}}} void selection_sort (link pointer, int num) {link TMP, BTMP; int I, min; for (i = 0; I data; btmp = null; while (tmp-> next) {if (min> tmp-> next-> Data) {min = tmp-> next-> data; btmp = tmp;} TMP = TMP-> Next;} Printf ("/ 40:% d / n", min); Pointer = delete_node (Pointer, BTMP); }}} link create_list (int Array [], int Num) {link TMP1, TMP2, POINTER; INT I; Pointer = (link) malloc (sizeof (node)); Pointer-> Data = array [0]; tmp1 = Pointer ; for (i = 1; i next = null; tmp2-> data = array [i]; tmp1-> next = TMP2 ; TMP1 = TMP1-> Next;} Return Pointer;} Link Concatenate (Link Pointer1, Link Pointer2) {LINK TMP; TMP = POINTER1; while (tmp-> next) TMP = TMP-> Next; TMP-> Next = Pointer2; Return Pointer1;} void main (void) {int Arr1 [] = {3,12,8,9,11 }; Link PTR; PTR = CREATE_LIST (Arr1,5); Selection_Sort (PTR, 5);} =============================== ========================================== 【Program 75】 Title:

Relax, count a simple topic.

1. Program analysis: 2. Source code: main () {INT i, n; for (i = 1; i <5; i ) {n = 0; if (i! = 1) n = n 1; IF (i == 3) n = n 1; if (i == 4) n = n 1; if (i! = 4) n = n 1; if (n == 3) Printf ("zhu HAO SHI DE SHI:% C ", 64 I);}} ===================================== ============================ 程序 程序 76] Topic: Write a function, enter N is an even number, the call function is 1/2 1/4 ... 1 / n, when entering N is odd, call function 1/1 1/3 ... 1 / n (utilization pointer function) 1. Program analysis: 2. Program Source code: main () # include "stdio.h" main () {float peven (), podd (), dcall (); float sum; int n; while (1) {scanf ("% d", & n) ; If (n> 1) Break;} if (n% 2 == 0) {Printf ("Even ="); SUM = DCALL (Peven, N);} else {Printf ("odd ="); sum = DCall (PODD, N);} printf ("% f", sum);} float peven (int N) {float s; int i; s = 1; for (i = 2; i <= n; i = 2 ) S = 1 / (float) i; return (s);} float podd (n) int N; {float s; int 1; s = 0; for (i = 1; i <= n; i = 2) S = 1 / (float) I; return (s);} float dcall (fp, n) float (* fp) (); int N; {float s; s = (* fp) (n); return (S );} =============================================== =============== 【Program 77】 Title: Fill in the exploration exercise (pointing to the pointer to the pointer) 1. Program analysis: 2. Program source code:

Main () {char * s [] = {"man", "Woman", "girl", "boy", "sister"}; char ** q; int K; for (k = 0; k <5; K ) {; / * What statements * / printf ("% s / n", * q) here;}} ======================= ======================================= 【程序 7 78】 Title: Find the oldest person And output. Please find out what problems in the program. 1. Program analysis: 2. Source code: #define n 4 # include "stdio.h" static struct man {char name [20]; int Age;} Person [N] = {"Li", 18, "Wang ", 19," zhang "," sun ", 22}; main () {struct man * q, * p; int i, m = 0; P = Person; for (i = 0; i agn) q = p ; m = Q-> Age;} printf ("% s,% d", (* q) .Name, (* Q) .age);} ============================================================================================================================================================================================================= ============ 【Program 79】 Title: String sort.

转载请注明原文地址:https://www.9cbs.com/read-73557.html

New Post(0)