Loop (print some small things)

Source: Internet
Author: User

Print multiples of 7 from 1 to 100
/*
int a=1; Define a Count value
while (a<=100) {//loop detect multiples of 100 or less 7
if (a%7==0) {//7 takes a remainder of zero is a multiple of 7
printf ("%d\n", a);
}
a++; Add 1 to the count after the loop
}
*/
Print numbers from 1 to 100 in single digit 7
/*
int a=1;
while (a<=100) {
if (a%10==7) {
printf ("%d\n", a);
}
a++;

} */
Print numbers from 1 to 100 for 10 bits 7
/*
int a=1;
while (a<=100) {
if ((a-70>=0) && (a-70<=9))
printf ("%d\n", a);
a++;
}*/
Printing 1 to 100 is not a multiple of 7 and does not contain 7 of the number
int a=1;
while (a<=100) {
if ((a%7!=0) && (a%10! = 7)) {
printf ("%d\n", a);



}
a++;
}



Random number
/*
[50,100];
int random=arc4random ()% (100-50+1) +50; Any number to 100 will be less than 100
printf ("%d", random); */
Console input n, use while to print n random numbers (range 10 to 30)
/*
[10,30];
int n=0;
printf ("Please enter a number:");
scanf ("%d", &n); n is the total number of cycles
while (n) {
printf ("%d\n", Arc4random ()% (30-10+1) +10); Print a random number from 10 to 30
n--; 1 reduction per cycle completion
}*/

Break (Terminate Loop), Contine (skip this cycle) two keywords
Do and loop, (at least once)
/*
do{



printf ("Soon after Class");
}while (0); * *
/*
int conut=0;
while (conut<30) {
printf ("%d cycles \ n", conut);
conut++;

}*/

For loop
/*
for (int conut=0;conut<30;conut++) {//First step, the loop variable (conut) executes only once
printf ("%d cycles \ n", conut); Part II, judging the conditions,
Third, if the statement is true, execute the increment, and continue to perform the second step for true return
}*/
Print multiples of 7 from 1 to 100
/*
for (int a=1;a<=100;a++) {
if (a%7==0) {

printf ("%d\n", a);
}
}  */
Print numbers from 1 to 100 in bits 7
/*
for (int conut =1;conut<=100;conut++) {
if (conut%10==7) {
printf ("%d\n", conut);
}
}
*/







Loop nesting
Print out 123
123
123
/*
for (int m=1;m<=3;m++) {
for (int i=1;i<=3;i++) {
printf ("%d", I);
}
printf ("\ n");
}*/
Print out 1
12
123
/*
for (int m=1;m<=3;m++) {
The difference between for (int i=1;i<=m;i++) {//And the previous question is in this line
printf ("%d", I);
}
printf ("\ n");


Print out multiplication tables
/*
for (int i=1;i<=9;i++) {
for (int j=1;j<=i;j++) {
printf ("%d*%d =%d\t", j,i,j*i);
}
printf ("\ n");
}

Loop (print some small things)

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.