"C Language Learning", C Primer Plus, chapter 6th C control Statements: Loops

Source: Internet
Author: User

Learning Summary

1, the circulation of the grammar and other languages are not bad, probably most of the language on the basis of the development of C, so much the same is not strange.

2, in the judgment expression, only 0 of C language is considered false, all non-0 value positive integers are considered true.

1 #include <stdio.h> 2 int main () {3         if (0) 4                 printf ("0 is true\n"), 5         if (1) 6                 printf ("1 is true\n"); 7         if ( -1) 8                 printf ("-1 is true\n"); 9         return 0;10}

Operation Result:

1 is True

-1 is True

3, the For loop has three expressions, the first expression to initialize the counter, the second expression to express restrictions on the computer, and a third expression to change the value of the counter. The For loop has a lot of flexibility, and expressions can have multiple expressions that coexist with the comma operator. But the use of too flashy words will tend to the code readability and maintenance costs increased, or honestly use for (i=0;i<n;i++) it.

4, Programming exercises (Title 4):

1 #include <stdio.h> 2 int main () {3         int i,j,mid,c,min,max; 4         c=10; 5         mid=c; 6 for         (i=0;i<c;i++) {7                 min=mid-i; 8                 max=mid+i; 9 for                 (j=0;j<max;j++) {Ten                         if (min-1) <=j&&j<max) {11                                 printf ("$");                         else{13                                 printf ("");                         }15                         if (j== (max-1)) {                                 printf ("\ n");                         }18         }19}20         printf ("\ n");         return 0;22}

Operation Result:

5, Programming exercises (title 16):

1 #include <stdio.h> 2  3 int main () {4         double m=100,v=0.08; 5         int i=1; 6 while         (i) {7                 m=m* (1+V)- 10; 8                 if (m>0) {9                         i++;10                 }else{11                         break;12                 }13         }14         printf ("%d years would over\n", I); 15         return 0;16}

Operation Result:

Years would over

"C Language Learning", C Primer Plus, chapter 6th C control Statements: Loops

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.