Classic C language procedure 100 cases (31-40) -------------------- Transfer from C Language Classics Forum

xiaoxiao2021-03-06  45

[Program 31] Title: Please enter the first letter of the day of the week to determine the week. If the first letter is the same, the second letter will continue to be judged. 1. Program analysis: Use the situation statement, if the first letter is the same, the judgment is determined by the case statement or the IF statement to determine the second letter.

2. Program source code: #include void main () {char letter; printf ("please infut the first letter of someday / n"); while ((Letter = getch ())! = 'Y' ) / * End * / {switch ("" ":" "); if (" please = getch ()) == 'A' is over when the letter is Y. ) PRINTF ("SATURDAY / N"); Else IF ((Letter = getCH ()) == 'u') Printf ("sunday / n"); Else Printf ("Data Error / N"); Break; Case ' F ': Printf ("friday / n"); Break; Case' M ': Printf ("Monday / N"); Break; Case' T ': Printf ("please input letter letter / n"); if (( Letter = getCH ()) == 'u') Printf ("Tuesday / N"); Else IF ((Letter = getCH ()) == 'h') Printf ("thursday / n"); Else Printf (" Data error / n "); Break; Case 'W': Printf (" Wednesday / N "); Break; Default: Printf (" Data Error / N ");}}} ========== ============================================================================================================================================================================================================= == [Program 32] Title: Press any key to change color, do you want to try! Please hurry up! 1. Program analysis: 2. Source code: #include void main (void) { Int Color; for (color = 0; Color <8; color ) {textbackgr Ound (color); / * Set text background color * / cprintf ("this is color% d / r / n", color); CPrintf ("press any key to continue / r / n"); getCh (); / * Enter characters can't see * /}} =============

============================================================================================================================================================================================================= [Program 33] Title: Learning Gotoxy () and CLRSCR () Functions 1. Program Analysis: 2. Source Code: #include void main (void) {ClrsCr (); / * Clear screen function * / Textbackground (2); gotoxy (1, 5); / * Positioning function * / cprintf ("Output At Row 5 Column 1 / N); Textbackground (3); Gotoxy (20, 10); CPrintf (" Output At Row 10 COLUMN 20 / N ");} ========================================== ====================== 程序 程序 34] Title: Exercise function call 1. Program analysis: 2. Source code: #include void Hello_World (void) {Printf ("Hello, World! / N");} void three_hellos (void) {int counter; for (counter = 1; counter <= 3; counter ) hello_world (); / * call this function * / } void main (void) {three_hellos (); / * call this function * /} ================================ =============================== 【Program 35】 Title: Text Color Settings 1. Program Analysis: 2. Source Code : #Include void main (void) {int color; for (color = 1; color <16; color ) {textcolor; / * Set text color * / cprintf ("this is color% d / r / n ", color);} TextColor (128 15); CPRINTF ("

This is blinking / r / n ");} ========================================= ======================= 【Program 36】 Title: Queuity within 100 Prouses 1. Program Analysis: 2. Source Code: #include #include "math.h" #define n 101main () {INT I, J, LINE, A [N]; for (i = 2; I

2. Program source code: #define n 10main () {INT i, J, min, tem, a [n]; / * input data * / printf ("please input ten num: / n"); for (i = 0; i a [j]) min = j; TEM = a [i]; a [i] = a [min] ; a [min] = TEM;} / * Output data * / printf ("after sorted / n"); for (i = 0; i

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

New Post(0)