Learning Summary
1. If...else ... Semantically it can be used, and other languages are not worse, just remember, one of the furthest distances in the world: I walk if you go else.
2, according to individual years of programming experience, too many if...else ... Nesting increases the readability and difficulty of maintaining code. Personally think the code is best not more than three layers if...else ... Nested, otherwise it is best to use a Boolean control process.
3, logical operator precedence:!>&&>| |
4. Running to the continue statement will cause the remainder of the iteration to be ignored, starting the next iteration. Continue are used only for loops, and break statements are used in loops and switch.
5, Programming questions (1):
1 #include <stdio.h> 2 3 int main () {4 int space=0,newline=0,other=0; 5 char ch; 6 printf ("Please E Nter something:\n "); 7 while (Ch=getchar ()! = ' # ') {8 if (ch== ' \ n ') {9 newline+=1;10 }else if (ch== ") {one space+=1;12 }else{13 other+=1;14 }15 }16 printf ("Space is%d\n", space), and printf ("NewLine is%d\ n ", newline); printf (" Other is%d\n ", other); return 0;20}
Operation Result:
Please enter something:
Hello world!
Hi Nihao.
#ABC
Space is 2
NewLine is 2
Other is 19
6, Programming questions (11):
1 #include <stdio.h> 2 #define ARTICHOKE_UNIT_PRIC 1.25 3 #define Beet_unit_price 0.65 4 #define Carota_unit_price 0.89 5 #define DISCOUNT 0.05 6 #define T_0_5 3.50 7 #define T_5_20 10.00 8 #define T_20_ 0.1 9 int main () {one D ouble a,b,c,ap,bp,cp,ac,bc,cc,sc,dc,tc;12 ap=artichoke_unit_pric;13 Bp=beet_unit_price; Cp=carota_unit_price; printf ("How many artichoke you want (pound):"), scanf ("%lf", &a), + if (a==0) return 0;18 19 printf ("How many beet you want (pound):"); scanf ("%lf", &b); if (b==0) return 0;22 23 printf ("How many carota you want (pound):"); scanf ("%lf", &c); if (c==0) return 0;26 (printf) ("\ n------unit price------\ n"); printf ("Artichoke's unit Price is $%.2f (one pound) \ n", AP); ET's Unit Price is $%.2f (one pound) \ n ", BP), printf (" Carota ' unit Price is $%.2f (one pound) \ n ", CP); rintf ("\n------ORDER------\ n "); printf (" artichoke:%.2fpound\n ", a); printf (" beet:%.2fpound\n ", b); PRI NTF ("carota:%.2fpound\n", c), Notoginseng printf ("\nartichoke is $%.2f", A*ap), ("\nbeet is $%.2f", B*BP); 39 printf ("\ncarota is $%.2f\n", C*CP), and sc=a*ap+b*bp+c*cp;41 printf ("\ntotal cost is $%.2f", SC); 42 dc=sc>100?sc*discount:0;43 printf ("\ndiscount is $%.2f", DC), "The \ntotal weight is%.2 F ", A+b+c); 0< (a+b+c) <=5) {tc=t_0_5;48}49 if (5< (a+b+c) && (a+b+c) <=20) {tc=t_5_20;51}52 if (a+b+c) >20) {$ tc=8+ (a+b+c) *0.1; }55 printf ("\nttransport Cost is $%.2f", TC), and the "\norder cost is $%.2f\n", SC-DC+TC); 57 58 Return 0;59}
Operation Result:
How many artichoke want (pound): 123
How many beet want (pound): 234
How many Carota want (pound): 343
------UNIT Price------
Artichoke ' s Unit price is $1.25 (one pound)
Beet ' s Unit Price is $0.65 (one pound)
Carota ' Unit Price is $0.89 (one pound)
------ORDER------
Artichoke:123.00pound
Beet:234.00pound
Carota:343.00pound
Artichoke is $153.75
Beet is $152.10
Carota is $305.27
Total Cost is $611.12
Discount is $30.56
Total weight is 700.00
Ttransport Cost is $78.00
Order Cost is $658.56
C language Learning, C Primer Plus, 7th C control statements: branching and jumping