c 语言loop语句,C语言循环语句(C language loop statement).doc

C语言循环语句(C language loop statement)

C语言循环语句(C language loop statement)

Output for 10 groups per line.

#include

Void, main ()

{int, I, J, flag, k=0;

For (i=500; i<=800; i++)

{flag=1;

For (j=2; j

If (flag==1) {printf ("%5d", "I"); k++;

If (k%10==0) printf ("\n");

}

}

Printf ("\nk=%d\n", K);

}

The second part: break and continue statements

The function of the 1.1.break statement: to end the for statement in this layer.

1.2. example: write function, ask s=1+2+3... Until the value of S is greater than the t end loop, the output s is the value, and the value of T is read through the keyboard.

#include

Void, main ()

{int, I, s=0, t;

Printf (enter the value of T:);

Scanf ("%d", &t);

For (i=1;; i++)

{s+=i;

If (s>t) break;

}

Printf ("i=%d\ns=%d\n", "I", "s");

}

T=8

-- >

I=1, s=1

I=2, s=3

I=3, s=6

I=4, s=10

1.3. nested break statements:

--- write function, output all the prime numbers between 500--800, each line for 10 groups for output.

#include

Void, main ()

{int, I, J, flag, k=0;

For (i=500; i<=800; i++)

{flag=1;

For (j=2; j

If (flag==1) {printf ("%5d", "I"); k++;

If (k%10==0) printf ("\n");

}

}

Printf ("\nk=%d\n", K);

}

2.1, continue statement function: skip the following statements that have not been executed in this layer and proceed to the next cycle.

2.2 example:

#include

Void, main ()

{int, I, s=0, k=0;

For (i=1; i<=5; i++)

{s+=i;

If (s>8), {printf ("****i=%d, s=%d, k=%d\n", I, s, K); continue;}

K+=s;

Printf ("i=%d, s=%d, k=%d\n", I, s, K);

}

}

I=1, s=1, k=1

I=2, s=3, k=4

I=3, s=6, k=10

****i=4, s=10, k=10

****i=5, s=15, k=10

The third part: character input and output

Taking the basic data types in C language: integer, real, character

--- char ch;

Ch>='0'&&ch<='9'

Ch>='A'&&ch<='Z'

Ch>='a'&&ch<='z'

3.1 character inputs and outputs:

(1) call printf and scanf

--printf function:

* * * in the C language, the form character%c is used to implement character output.

Such as:

#include

Void, main ()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值