C language programming-program exercises (below)
Some simple operations in C language.
Swap two numbers:
# Include <stdio. h> int main (void) {int I = 3; int j = 5; int t; // exchange the values of I and j t = I; I = j; j = t; printf ("I = % d, j = % d \ n", I, j); return 0 ;}
Outputs the pyramid of any character layer:
# Include <stdio. h> main () {int a, I, j; char c; printf ("Enter the number of pyramid layers, 30: \ n"); scanf ("% d ", & a); printf ("Enter the characters to output: \ n"); scanf ("% c", & c); for (I = a; I> 0; I --) {printf ("% * s", I, ""); for (j = 0; j <(a-I) * 2-1 ); j ++) {printf ("% c", c);} printf ("\ n");} return 0 ;}
Running result:
Operation:
# Include <stdio. h> int main (void) {/* float I; I = 51/4; printf ("% f \ n", I ); printf ("% d \ n", 3% 3, 13%-3,-13% 3,-13%-3,-13% 23, 3% 5); */int m; int k = 10; m = (21> 3) & (k = 5); // m is a Boolean value, k = 5 is true. False is true only when k = 0, that is, 0 is false, and other numbers are true printf ("m = % d, k = % d \ n ", m, k); // when the true or false values of m cannot be determined on the left side, the right side is executed. If the true or false values of m are determined on the left side, the right side is not executed. // & When the expression on the left is false, the expression on the right will certainly not execute // | if the expression on the left is true, return 0 will not be executed for the expression on the right ;}
Sort three numbers:
# Include <stdio. h> int main (void) {double I, j, k; printf ("Enter three numbers (separated by spaces ):"); scanf ("% lf", & I, & j, & k); if (I> j) {if (I> k) {printf ("maximum value: % lf \ n", I); if (j> k) printf ("the order of numbers is: % lf> % lf \ n ", I, j, k); elseprintf (" the order of numbers is % lf> % lf \ n ", i, k, j);} else {printf ("maximum value: % lf \ n", k); if (I> j) printf ("number size order: % lf> % lf \ n ", k, I, j); elseprintf (" the order of numbers is % lf> % lf \ n ", k, j, I) ;}} else {if (j> k) {printf ("maximum value: % lf \ n", j); if (I> k) printf ("number size order: % lf> % lf \ n", j, I, k); elseprintf ("number size order: % lf> % lf \ n ", j, k, I);} else {printf (" maximum value: % lf \ n ", k ); if (I> j) printf ("the order of numbers is % lf> % lf \ n", k, I, j ); elseprintf ("number size order: % lf >%lf \ n", k, j, I) ;}} return 0 ;}
Zookeeper
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.