"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 intMain () {3         if(0)4printf"0 is true\n");5         if(1)6printf"1 is true\n");7         if(-1)8printf"-1 is true\n");9         return 0;Ten}

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 intMain () {3         intI,j,mid,c,min,max;4C=Ten;5Mid=C;6          for(i=0; i<c;i++){7min=mid-i;8Max=mid+i;9                  for(j=0; j<max;j++){Ten                         if((min-1) <=j&&j<max) { Oneprintf"$"); A}Else{ -printf" "); -                         } the                         if(j== (max-1)){ -printf"\ n"); -                         } -                 } +         } -printf"\ n"); +         return 0; A}

Operation Result:

5, Programming exercises (title 16):

1#include <stdio.h>2 3 intMain () {4         Doublem= -, v=0.08;5         intI=1;6          while(i) {7m=m* (1+V)-Ten;8                 if(m>0){9i++;Ten}Else{ One                          Break; A                 } -         } -printf"%d years would over\n", i); the         return 0; -}

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.