Classic C language program 100 cases (91-100) ------------ Transfer from C Language Classic Forum

xiaoxiao2021-03-06  49

[Program 91] Title: Time Function Example 11. Program Analysis: 2. Source Code: #include "stdio.h" #include "time.h" void main () {time_t lt; / * Define a longint time varible * / lt = time (null); / * system time and date * / printf (ctime (<)); / * English format output * / printf (asctime (localtime (<)))); / * TRANFER TOTM * / PRINTF (asctime (gmtime (<))); / * Tranfer to greenwich time * /} =============================== =============================== 【程序 9 92】 Title: Time function example 21. Program analysis: 2. Program source code : / * Calculate Time * / # include "time.h" #include "stdio.h" main () {time_t start, end; int i; start = time (null); for (i = 0; i <3000; i ) {Printf ("/ 1/1/1/1/1/1/1/1/1/1);} end = time (null); printf (" / 1: the Different IS% 6.3 F / N ", DIFFTIME (End, start));} ===================================== ========================== 【Program 93】 Title: Time function example 31. Program analysis: 2. Sample source code: / * Calculate Time * / # include "time.h" #include "stdio.h" main () {clock_t start, end; int i; double var; start = clock (); for (i = 0; i <1000; i ) { Printf ("/ 1/1/1/1/1/1/1/1/1/1/1/1);} end = clock (); Printf (" / 1: The Different IS% 6.3F / N " (end-start);} ====================================================================================================================================

================================================ 【程序 9 94 】 Title: Time Function Example 4, a guess number game, judge that a person is slow.

(Moderator first school) 1. Procedure analysis: 2. Source code: #include "time.h" #include "stdlib.h" #include "stdio.h" main () {char C; clock_t start, End; Time_t A, B; Double Var; INT I, GUESS; SRAND (Time (NULL)); Printf ("Do You Want To Play IT. ('Y' or 'N') / N"); loop: while ((c = getChar ()) == 'y') {i = rand ()% 100; Printf ("/ NPLEase: / N"); start = clock (); a = time (null) Scanf ("% D", & guess; while (guess! = i) {if (Guess> i) {printf ("please input a little smaller./n" ";scanf("%d" ,und); } else {printf ("please input a little bigger./n" ";scanf ("%d" ,und );}}} }b=time(null );printf("/1: IT TOOK YOU% 6.3f Seconds / N ", VAR = (Double) (end-start) /18.2); Printf (" / 1: IT TOOK You% 6.3f Seconds / N / N ", DiffTime (B, A)); IF (var <15) Printf ("/ 1/1 you are very very clever! / 1/1 / n / n"); Else IF (var <25) Printf ("/ 1/1 you are normal! / 1 / 1 / N / N "); elseprintf (" / 1/1 you are stupid! / 1/1 / n / n "); Printf (" / 1/1 congraDulation / 1/1 / n / n "); Printf ("THE NUMBER You Guess IS% D", I);} Printf ("/ NDO You Want To try it again? (/" Yy / ". OR ./" n / ") / n"); if (((( C = getCH ()) == 'y') goto loop;} ================ ============================================== 【程序 程序 95】 Topic: Home Financial Management Apprassment 1. Program Analysis: 2. Source Code: / * Money Management System * / # include "stdio.h" #include "dos.h" main () {file * fp; struct date d ;

Float SUM, CHM = 0.0; INT LEN, I, J = 0; INT C; CHAR CH [4] = "", CH1 [16] = "", Ch Time [12] = "", Chshop [16], Chmoney [8]; PP: CLRSCR (); SUM = 0.0; gotoxy (1, 1); Printf ("| ----------------------- -------------------------------------------------- | "); gotoxy (1, 2); Printf (" | Money Management System (C1.0) 2000.03 | "); gotoxy (1, 3); Printf (" | ----------- -------------------------------------------------- -------------- | "); gotoxy (1, 4); Printf (" | - Money Records - | - Today Cost List - | "); gotoxy (1 , 5); Printf ("| --------------------------------------------------------------------------- --------------------------------------- - | | |); Gotoxy (1,7); Printf ("| | | | |"); gotoxy (1, 8); printf ("| -------------- | "); gotoxy (1, 9); Printf (" | THGS: ------------------ | | "); gotoxy (1, 10); Printf (" | | | | | "); Gotoxy (1,11); Printf (" | ---------------- | | "); gotoxy (1,12); printf ("| COST: ---------- | |"); gotoxy (1, 13); Printf ("| | | | |"); gotoxy (1,14); printf ("| --------- | | "); gotoxy (1,15); Printf (" | | | "); gotoxy (1, 16); Printf (" | | | "); gotoxy (1, 17); Printf ("| | | | "); gotoxy (1,18); printf (" | | | "); gotoxy (1,19); printf (" | | | "); gotoxy (1, 20); printf (" | | | | "); gotoxy (1,21); printf (" | | | "); gotoxy (1,22); Printf (" | | | "); gotoxy (1, 23); printf (" | ---- -------------------------------------------------- --------------------- | "); i = 0; getdate (& D); sprintf (chtime,"% 4D.% 02d.% 02d ", D .da_year, d.da_mon, d.da_day); for (;;) {gotoxy (3, 24); Printf ("tab __browse cost list esc __quit"); gotoxy (13, 10); Printf (");" GotoxY (13, 13); Printf (""); gotoxy (13, 7); Printf ("% s"

, chtime); J = 18; CH [0] = getCH (); if (CH [0] == 27) Break; strcpy (chshop, ""); strcpy (chmoney, "); if (ch [0 ] == 9) {mm: i = 0; fp = fopen ("HOME.DAT", "R "); gotoxy (3,24); printf (""); gotoxy (6, 4); Printf (" List records "); gotoxy (1,5); printf (" | -------------------------------- --- | "); Gotoxy (41, 4); Printf (" "); gotoxy (41, 5); Printf (" | "); while (fscanf (fp,"% 10S% 14S% F / N " , chtime, chshop, & chm)! = EOF) {if (i == 36) {getCH (); i = 0;} IF ((i% 36) <17) {gotoxy (4, 6 i); printf (""); gotoxy (4,6 i);} elseif ((i% 36)> 16) {gotoxy (41, 4 i-17); Printf (""); gotoxy (42, 4 i -17);} i ; sum = sum CHM; Printf ("% 10S% -14S% 6.1f / n", chtime, chshop, chm);} gotoxy (1, 23); printf ("| -------------------------------------------------- ---------------------- | "); gotoxy (1,24); Printf (" | | "); gotoxy (1,25); Printf "| ------------------------------------------------------------------------------- --------------------------- | "); gotoxy (10,24); Printf (" Total IS% 8.1F $ ", SUM ); fclose (fp); gotoxy (49, 24); Printf ("press any key to ....."); getCh (); goto pp;} else {while (ch [0]! = '/ r ') {IF (j <10) {strncat (chtime, ch, 1); J ;} if (ch [0] == 8) {LEN = Strlen (chtime) -1; IF (j> 15) {len = len 1; j = 11;} strcpy (ch1, "); j = j-2; strncat (ch1, chtime, len); strcpy (chtime, ""); strncat (chtime, ch1, len-1); gotoxy (13, 7); Printf ("");} gotoxy (13, 7); Printf ("% s", chtime); ch [0] = getCH (); if (CH [0] == 9) goto mm; if (CH [0] == 27) exit (1);} gotoxy (3,24); Printf (""); gotoxy (13, 10); j = 0; CH [0] = getCH (); while (ch [= 0]! = '/ r') {IF (j <14) {strncat (chshop, ch, 1); J ;

} IF (CH [0] == 8) {LEN = Strlen (chshop) -1; strcpy (ch1, "); j = j-2; strncat (chshop, len); strcpy (chshop," ); strncat (chshop, ch1, len-1); gotoxy (13, 10); Printf ("");} gotoxy (13, 10); Printf ("% s", chshop); ch [0] = getCH (); gotoxy (13, 13); j = 0; CH [0] = getCH (); while (ch [0 (= 0]! = '/ r') {IF (j <6) {strncat (chmoney, ch , 1); J ;} IF (CH [0] == 8) {LEN = Strlen (chmoney) -1; strcpy (ch1, "); j = j-2; strncat (ch1, chmoney, len); Strcpy (chmoney, "); strncat (chmoney, ch1, len-1); gotoxy (13, 13); Printf (" ");} gotoxy (13, 13); Printf ("% s ", chmoney); CH [0] = getCH ();} = 0) || (Strlen (chmoney) == 0)) Continue; IF ((fp = fopen ("home.dat", "A "))! = Null); FPRINTF (FP,"% 10S% 14S% 6S ", chtime, chshop, chmoney; fputc ('/ n', fp); fclose (fp); i ; gotoxy (41, 5 i); Printf ("% 10S% -14S% -6s", chtime, chshop, chmoney);}}} ======================== ======================================= 【程序 9 96】 Title: Computing string neutron The number of strings appears 1. Program analysis: 2. Source code: #include "string.h" #include "stdio.h" main () {char str1 [20], str2 [20], * p1, * p2; INT SUM = 0; Printf ("please input two strings / n"); scanf ("% S% S", STR1, STR2); P1 = STR1; P2 = STR2; while (WHILE) * p1! = '/ 0') {if (* p1 == * p2) {while (* p1 == * p2 && * p2! = '/ 0') {p1 ; p2 ;}} elsep1 ; if (* p2 == '/ 0') SUM ; p2 = str2;} printf ("% d"

, SUM); getCH ();} ========================================= ===================== 【Program 97】 Topic: Enter some characters from the keyboard, send them onto the disk until it is entered. 1. Program analysis: 2. Program source code: #include "stdio.h" main () {file * fp; char ch, filename [10]; scanf ("% s", filename); if ((fp = fopen) (Filename, "W")) == null) {PrintF ("canNot Open file / n"); exit (0);} ch = getchar (); ch = getchar (); while (ch! = '#' ) {FPUTC (CH, FP); PUTCHAR (CH); CH = getchar ();} fclose (fp);} ======================= ============================================================================================== 【Program 98】 Strings, convert all lowercase letters into uppercase letters, then output to a disk file "Test" saved. Entered string! end.

1. Program analysis: 2. Source code: #include "stdio.h" main () {file * fp; char STR [100], filename [10]; int i = 0; if ((fp = fopen) TEST "," W ")) == null) {PrintF (" Cannot Open THE FILE / N "); exit (0);} Printf (" Please Input A String: / N "); Gets (STR); while (STR [I]! = '!) {IF (STR [I]> =' A '&& STR [I] <=' Z ') STR [I] = STR [I] -32; FPUTC (STR [I ], FP); I ;} fclose (fp); fp = fopen ("test", "r"); FGETS (STR, Strlen (STR) 1, FP); Printf ("% s / n", STR ); fclose (fp);} ================================================ ==================== 【Program 99】 Title: There are two disk files A and B, and each stored a line of letters, requiring mergers in the two files. (Arrange in alphabetical order), output into a new file C.

1. Program analysis: 2. Source code: #include "stdio.h" main () {file * fp; int i, j, n, ni; char C [160], t, ch; if ((fp = FOPEN ("A", "R")) == NULL) {Printf ("File A Cannot Be Opened / N"); exit (0);} Printf ("/ N a contents are: / n"); for (i = 0; (CH = FGETC (FP))! = EOF; i ) {C [i] = ch; PUTCHAR (C [i]);} fclose (fp); ni = i; if ((fp = FOPEN ("B", "R")) == NULL) {Printf ("File B Cannot Be Opened / N"); Exit (0);} Printf ("/ N B Contents Are: / N"); for (i = 0; (CH = FGETC (FP))! = EOF; i ) {C [i] = ch; PUTCHAR (C [i]);} fclose (fp); n = i; for (i = 0 ; i c [j]) {t = c [i]; c [i] = c [j] ; c [j] = t;} Printf ("/ n c file is: / n"); fp = fopen ("c", "w"); for (i = 0; i

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

New Post(0)