- 3
- 0
- 约1.72千字
- 约 46页
- 2020-03-12 发布于福建
- 举报
第6章 程序的控制结构(2)——循环;6.1循环结构;循环——while语句,for语句;while语句;do-while语句;for语句;注意 循环变量的使用;for语句;选择三种循环的一般原则;注意;例:计算 n!=1×2×…n;循环次数已知,首先考虑用for循环语句
#include stdio.h
main()
{
int i, n; /* i是循环变量*/
long p=1; /* 存放阶乘的值 */
printf(Please enter n:);
scanf(%d,n);
for(i=1; i=n; i++)
{
p=p*i;
}
printf(%d!=%ld\n,n,p);
};例:计算 n!=1×2×…n;只猜1次;猜数游戏用到的库函数;例;例;#include stdlib.h
#include stdio.h
#include time.h
main()
{
int magic;
int guess;
int counter;
srand(time(NULL));
magic = rand() % 100 + 1;
counter = 0;
do
原创力文档

文档评论(0)