iOS Learning Notes---C language the third day

Source: Internet
Author: User

Loop structure : While loop Do...while loop (almost unused) for loop (most used)

Characteristics: When a given condition is established, a program section is executed repeatedly until the condition is not established.

The given condition is a cyclic condition, which executes repeatedly in the program fragment loop body.

One, while loop

while (conditional expression) {

Loop statement;

}

#import <Foundation/Foundation.h>intMainintargcConst Char*argv[]) {    inti =0;  while(i<Ten) {printf ("hello,word!\n"); I++; }    return 0;}
1#import <Foundation/Foundation.h>2 3 intMainintargcConst Char*argv[])4 {5 //use while to print a multiple of 7 between 1~100. 6 //int i = 1,d;7 //While (i<=100) {8 //d = i%7;9 //if (d = = 0) {Ten //printf ("%d\t", I); One //        } A //         - //i++; - //    } the //use while to print the number of bits 7 between 1~100 - //int i = 1,d; - //While (i<=100) { - //d = i%10; + //if (d = = 7) { - //printf ("%d\t", I); + //        } A // at //i++; - //    } -     //use while to print out between 1~100? 10 bits of 7 - //int i = 1,d; - //While (i<=100) { - //d = I/10; in //if (d = = 7) { - //printf ("%d\t", I); to //        } + //         - //i++; the //    } *     //use while to print a multiple of 1~100 that is not 7 and does not contain a number of 7 $     inti =1, d,a,b;Panax Notoginseng      while(i<= -) { -D = i/Ten; theA = i%7; +b = i%Ten; A         if(d! =7&&a!=0&&b!=7) { theprintf"%d\t", i); +         } -          $i++; $     } -  -     return 0; the}

random number arc4random ()-----Returns a pseudo-random number

?
1 2 //得到0到30之间的数    printf("%d",arc4random()%31);

// get a number between ten to

printf("%d",arc4random()%+10 );

Fetch (M,N) between the random number printf ("%d", Arc4random ()% (n-m+1) +m);

1    //The user outputs from the console a N,? Use while to print n random numbers with a range of [30~70] to find the most significant value in n random numbers2#import <Foundation/Foundation.h>3 4 intMainintargcConst Char*argv[])5 {6     intn,i,max=0, B;7printf"Enter a number n:");8scanf"%d",&n);9      while(i<N) {Tenb = arc4random ()% A+ -; Oneprintf"%d", b); A         if(Max <b) { -Max =b; -         } thei++; -          -          -     } +printf"\nmax=%d", max); -     return 0; +}

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.