C语言 入门知识 习题演练.docC语言 入门知识习题演练
Cyclic strueture
While (condition) {body} / /
output ****************;
#include<stdio. h>
Int, main () {
Int i=0;
Wh订e (i<10) {
Printf (*);
I++; //i=i+l;
}
Printf ("\n");
}
for (initial condition, cycle condition, cyclic increment)
/ / loop
/ / first performs initialization conditions / execution cycle conditions -- > body circulation and increase circulation conditions -- > 一 > 一 > loop - circular increment
For• ****************
#include<stdio. h>
Int, main () {
The use of for / / output cycle
For (int i=0: i<10: i++) {
Printf (*);
}
Printf ("\n");
print all the numbers that 0—1000 can be divisible by 3 and
7 with the for loop and calculate the number
#include<stdio. h>
Int i=0;
Int count = 0; / / this is a counter variable
For ((i<=100: i++) {
If (i%5==0) {
Printf ("%d\n", I);
Count++; / / each increment 1
}
}
Printf ("a total of%d numbers can be divisible by 5 by \n",
"count");
}
#include<stdio. h>
Int, main () {
Calculate all 3 digits in / / the number of daffodils
Int i = 100;
Int Shi = 0:
Int Bai = 0:
For ((i<1000; i++) {
Ge = i%10;
Shi = i/10%10;
Bai = i/100;
If (ge*ge*ge+shi*shi*shi+bai*bai*bai = = I) {
Printf ("%d is narcissus number \n", I);
The dead loop in the 4. for loop
#include<stdio. h>
Int, main () {
Int i=0;
(for: i<10: i++) {/ / loop condition is empty (i〈10) or if the circular increment is empty (i++), the cycle of death
Printf ("%d\n", I);
do {
/ / loop
}while (condition);
Explana ti on: the while loop is the firs t to det ermine the loop condition, and the condition is fulfilled. The while loop executes at least 0 times.
Do. . While first executes the after judgment condition, and do. . While performs at least 1 times.
[Focus] the for loop is already aware of the number of cycles.
Summing:
#include<stdio. h>
Int, main () {
Do{
Sum = sum+i;
I++;
}wh订e (i<=1000);
Printf ("%d\n", sum);
}
monkeys eat peaches problem
#include<stdio. h>
Int, main () {
I
C语言 入门知识 习题演练 来自淘豆网m.daumloan.com转载请标明出处.