题目
分别用三种循环语句(while语句、do-while语句、for语句)各编写一个程序实现求1 20的累乘,即:
1 × 2 × 3 × …… × 20
总结出三种循环语句哪种实现起来方便、灵活.
1 × 2 × 3 × …… × 20
总结出三种循环语句哪种实现起来方便、灵活.
提问时间:2021-04-01
答案
//while写法
#include <stdio.h>
main()
{
long total=1, i=1;
while(i<=20)
{
total = total * i;
i++;
}
printf("result=%d ", total);
}
//do-while写法
#include <stdio.h>
main()
{
long total=1, i=1;
do
{
total = total * i;
i++;
} while(i<=20);
printf("result=%d ", total);
}
//for写法
#include <stdio.h>
main()
{
long total=1, i;
for(i=1; i<=20; i++)
total = total * i;
printf("result=%d ", total);
}
#include <stdio.h>
main()
{
long total=1, i=1;
while(i<=20)
{
total = total * i;
i++;
}
printf("result=%d ", total);
}
//do-while写法
#include <stdio.h>
main()
{
long total=1, i=1;
do
{
total = total * i;
i++;
} while(i<=20);
printf("result=%d ", total);
}
//for写法
#include <stdio.h>
main()
{
long total=1, i;
for(i=1; i<=20; i++)
total = total * i;
printf("result=%d ", total);
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1万的大写怎么写
- 2我国古代与太阳有关的神话(除夸父追日)有什么,你还知道有关太阳的哪些诗句?
- 3221瓦几小时一度电
- 4甲、乙两数的最大公因数是3,最小公倍数是30,已知甲数是6,乙数是_.
- 5求函数y=tanx/1-tan^2x最小正周期
- 6数学配套练习册北师大版八上p46业9题
- 7The thing itself is not important.
- 8照样子写词语 :嘴巴一抿 ( ) ( ) ( ) ( )( )
- 9如图,已知△ABC≌△DCE≌△HEF,三条对应边BC、CE、EF在同一条直线上,连接BH,分别交AC、DC、DE于点P、Q、K,若△DQK的面积为2,则图中三个阴影部分的面积和为_.
- 10一个入一个肉念什么
热门考点
- 1说明性文章(介绍一种商品)
- 2课文《散步》的:这南方初春的田野,大块小块的新地·······一直到:田里的冬水也咕咕地起着水
- 3若⊙O的弦AB的长为8cm,O到AB的距离为43cm,弦AB所对的圆心角为_.
- 4已知X1和X2是方程2X的平方加3X减4等于0的两个根,那么x1减x2等于多少
- 5算式:1.100又9998x99.2.49又5049x50
- 6英语翻译
- 7一台挂钟;一点钟敲一下,二点钟敲两下,三点钟.12点敲十二下,每半小时敲一下,这台挂钟一昼夜共要敲多
- 8己之不欲,勿施于人.什么意思
- 9在一条长100米的通路两侧,从头到尾每隔2米在一棵树,按2棵杨树,一颗柳树的规律栽植.杨树,柳树各占植树总棵
- 101.Mr.Smith offers us some advice on how to write a good composition,which _____ the following steps.