Classic C language procedure 100 cases (61-70) -------------------- Transfer from C Language Classics Forum

xiaoxiao2021-03-06  45

[Procedure 61] Topic: Print Yang Hui triangle (requirement 10 lines as shown below) 1. Program analysis: 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 2. Program source code : Main () {INT I, J; INT A [10] [10]; Printf ("/ n"); for (i = 0; i <10; i ) {a [i] [0] = 1; A [i] [i] = 1;} for (i = 2; i <10; i ) for (j = 1; j

1. Program analysis: 2. Program source code: #include "stdio.h" #include "graphics.h" Main () {Int i, j, driver = VGA, Mode = Vgahi; Initgraph (& Driver, & Mode, "" ); setBkcolor (YELLOW); for (i = 50; i <= 230; i = 20) for (j = 50; j <= 230; J ) PUTPEL (i, j, 1); for (j = 50; J <= 230; j = 20) for (i = 50; i <= 230; i ) PUTPIEL (i, j, 1);} ================== ==================================================== 【Program 63】 Title: Painting Ellipse Ellipse 1. Program Analysis: 2. Source Code: #include "stdio.h" #include "graphics.h" #include "conoe.h" main () {int x = 360, y = 160, driver = VGA, MODE = VGAHI; INT NUM = 20, I; INT TOP, BOTTOM; INITGRAPH (& Driver, & Mode, "); TOP = Y-30; bottom = Y-30; for (i = 0; i

1. Program analysis: 2. Source code: #include "stdio.h" #include "graphics.h" #include "conoe.h" main () {int DRIVER = VGA, MODE = VGAHI; INT I, NUM = 15, TOP = 50; INT LEFT = 20, Right = 50; INITGRAPH (& Driver, & Mode, ""); for (i = 0; i

1. Program analysis: 2. Source code: #include "graphics.h" #include "math.h" #include "dos.h" #includ "conio.h" #include "stdlib.h" #include "stdio .h "#include" stdarg.h "#define MAXPTS 15 # define PI 3.1415926struct PTS {int x, y;}; double AspectRatio = 0.85; void LineToDemo (void) {struct viewporttype vp; struct PTS points [MAXPTS]; INT I, J, H, W, Xcenter, Ycenter; int Radius, Angle, Step; Double Rads; Printf ("MoveTo / LineTo DemonStration); GetViewSettings (& VP); H = VP.BOTTOM - VP.TOP; W = vp.right - vp.Left; xcenter = W / 2; / * determine the center of circle * / ycenter = h / 2; radius = (h - 30) / (aspectratio * 2); Step = 360 / maxpts; / * Determine # of increments * / ang = 0; / * begin at zero degRees * / for (i = 0; i

================================= 程序 程序 66] Title: Input 3 numbers A, B, C, according to the size Sequential output. Program analysis: Using the pointer method. 2. Program source code: / * Pointer * / main () {INT N1, N2, N3; INT * POINTER1, * POINTER2, * POINTER3; Printf ("Please Input 3 Number: N1, N2, N3:"); scanf ("% D,% D,% D", & n1, & n2, & n3); Pointer1 = & n1; Pointer2 = & n2; Pointer3 = & n3; if (n1> n2) SWAP (Pointer1, Pointer2); if (n1> n3) SWAP (Pointer1, Pointer3); IF (N2> N3) Swap (Pointer2, Pointer3); Printf ("The sorted number are:% D,% D,% D / N", N1, N2, N3);} SWAP ( P1, P2) INT * P1, * P2; {INT P; P = * p1; * p1 = * p2; * p2 = p;} ================== ==================================================== 【Program 67】 Title: Enter an array, the maximum exchange, the minimum exchange, and output an array with the last element. 1. Program analysis: There is a problem with the answer in Tan Haoqiang's book.

2. Program source code: main () {int number [10]; input (number); max_min (number); output (number);} INPUT (Number) int Number [10]; {INT i; for (i = 0; I <9; i ) scanf ("% d,", & number [i]); scanf ("% d", & number [9]);} max_min (array) int Array [10]; {INT * MAX , * MIN, K, L; INT * P, * Arr_end; Arr_end = array 10; max = min = array; for (p = array 1; p * max) MAX = P; ELSE IF (* P <* min) min = p; k = * max; L = * min; * p = array [0]; array [0] = L; L = * p; * p = array [9]; array [9] = k; k = * p; return;} Output (array) int Array [10]; {INT * P; for (p = array; p array; p - 1); * array = array_end; m -; if (m> 0) Move (array, n, m);} === =============

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

New Post(0)