100 cases of classic C language procedures (41-50) ------------------ Transfer from C Language Classics Forum

xiaoxiao2021-03-06  46

[Program 41] Topic: Learn Static Define Static Variables Usage 1. Program Analysis: 2. Source Code: #inClude "stdio.h" varFunc () {int var = 0; static int static_var = 0; printf ("/ 40: VAR EQUAL% D / N ", var); Printf (" / 40: static var equals); static_var); Printf ("/ n"); var ; static_var ;} void main () {INT i; for (i = 0; i <3; i ) varFunc ();} =============================== ============================================================================================================================================================== . Source code: #include "stdio.h" main () {INT i, NUM; NUM = 2; for (i = 0; i <3; i ) {printf ("/ 40: the num equal% d / N ", NUM); Num ; {Auto Int Num = 1; Printf (" / 40: THE INTERNAL BLOCK NUM EQUAL% D / N ", NUM); NUM ;}}} ========== ============================================================================================================================================================================================================= == [Program 43] Title: Learn another use of Static.

1. Program analysis: 2. Source code: #include "stdio.h" main () {INT I, NUM; NUM = 2; for (i = 0; i <3; i ) {printf ("/ 40: THE NUM EQUAL% D / N ", NUM); Num ; {Static Int Num = 1; Printf (" / 40: THE INTERNAL BLOCK NUM EQUAL% D / N ", NUM); NUM ;}}} ==== ============================================================================================================================================================================================================= ======== [Program 44] Title: Learn to use External usage. 1. Program analysis: 2. Program source code: #include "stdio.h" int A, b, c; void add () {Int a; a = 3; c = a b;} void main () {A = B = 4; add (); Printf ("The value of c is equals%% d / n", c);} ===================== ================================================= 【Procedure 45】 Title: Learn to use Register Define variables.

1. Program analysis: 2. Source code: void main () {register INT i; int TMP = 0; for (i = 1; i <= 100; i ) TMP = I; printf ("the Sum IS% D / n ", TMP);} ========================================== ==================== 【Program 46】 Title: Macro #define command exercise (1) 1. Program analysis: 2. Source code: #include "stdio. H "#define true 1 # define false 0 # define sq (x) (x) * (x) void main () {int Num; int Again = 1; Printf (" / 40: Program Will Stop if Input Value Less Than 50./n" ";while "{Printf ("/40:please input number ===>"); scanf ("% d", & num); printf ("/ 40: the square for this number IS% D / N ", SQ (NUM)); if (num> = 50) again = true; else again = false;}} ===================== ================================================= 【Program 47】 Title: Macro #define Command Exercise (2) 1. Program Analysis: 2. Program source code: #include "stdio.h" #define Exchange (a, b) {/ / * macro definition allows the case where two clothes orders are allowed, Plus "/" * / int T; / t = a; / a = b; / b = t; /} void main (void) {INT x = 10; int y = 20; printf ("x =% D; Y =% D / N ", x, y); Exchange (X, Y); Printf (" x =% D; Y =% D / N ", x, y);} ==== ==============

==================================================== 【Program 48】 Title: Macro #define command exercises (3) 1. Program analysis: 2. Source code: #define lag> #define sma <#define EQ == # include "stdio.h" void main () {int i = 10; int = J = 20; IF (i LAG J) Printf ("/ 40:% d Larger Than% D / N", I, J); ELSE IF (I EQ J) Printf ("/ 40:% D Equal TO% D / N ", I, J); ELSE IF (I SMA J) Printf (" / 40:% D Smaller Than% D / N ", I, J); ElsePrintf (" / 40: No Such value./N " );} =============================================== =============== [Program 49] Title: #if #ifdef and #ifndef integrated application.

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

New Post(0)