当前位置:网站首页>C语言练习题目+答案:26-30
C语言练习题目+答案:26-30
2022-07-21 02:05:00 【aaawitch】
26.while(条件表达式)循环体,假设循环体里面没有break、continue、return、goto语句等,条件表达式的执行次数总是比循环体的次数多一次。
27.
int main()
{
int a = 0, b = 0;
for (a = 1, b = 1; a <= 100; a++)
{
if (b >= 20)break;
if (b % 3 = 1)
{
b = b + 3;
continue;
}
b = b - 5;
}
printf("%d\n", a);
return 0;
}
程序的输出结果是?
A.10
B.9
C.8
D.7
、答案:C.8
28.编写程序数一下1-100中的所有整数中出现多少个数字9
int main()
{
int a = 0;
int count = 0;
for (a = 1; a <= 100; a++)
{
if (a % 10 == 9)
count++;
if (a / 10 == 9)
count++;
}
printf("%d\n", count);
return 0;
}
29.计算1/1 - 1/2 + 1/3 - 1/4 + 1/5……+ 1/99 - 1/100的值,打印出结果
int main()
{
int i = 0;
double sum = 0.0; //用int,1/2的结果是0;所以要改为double
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
sum -= 1.0 / i;
else
sum+=1.0/ i;
}
printf("%lf\n", sum); //这里的%d也要改为lf,double; %f---float浮点型
return 0;
}
第二种更简便方法如下:
int main()
{
int i = 0;
double sum = 0.0;
int flag = 1;
for (i = 1; i <= 100; i++)
{
sum += flag*1.0 / i;
flag = -flag; //这里就会正负交替
}
printf("%lf\n", sum);
return 0;
}
30.求10个整数中的最大值
int main()
{
int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
int max = arr[0];
int i = 0;
for (i = 0; i < 100; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
printf("%d\n", max);
return 0;
}
边栏推荐
- Okaleido tiger NFT is about to log in to the binance NFT platform. Are you looking forward to it?
- 【翻译】开发人员的技术写作
- 【云原生】SQL(及存储过程)跑得太慢怎么办?
- Getting started with ctfshow web (file upload)
- 2D array theme
- Nonext fast medical image segmentation network based on MLP
- 后深度学习时代,推荐系统向何处去?
- pytorch利用nn.unfold重新实现卷积操作
- 基于JSP/SERVLET实现的人脸识别考勤系统
- CAPL中的CAN消息:声明、发送和接收
猜你喜欢
Synthesis of tetramethyl rhodamine TRITC modified peptide nucleic acid PNA | TRITC PNA | fluorescein labeled PNA
乙二胺改性金属有机骨架材料MIL-101(Cr)|功能MOFs/聚合物复合材料|ZIF-8/丙烯酸十四-十六酯共聚物(ZIF-8/P(TDA--HDA)
Experimental requirements of cy5-pna cyanine dye Cy5 labeling PNA
一文读懂 MongoDB 和 MySQL 的差异
What impact will Microsoft's closure of basic authentication have on enterprises and employees?
金属有机框架MIL-101(Cr)负载壳聚糖材料|MIL-101(Cr)@CS|甘草次酸(GA)修饰金属有机框架材料UiO-66-NH2(UiO-66- NH2-GA)
基于ssm框架的大学生社团管理系统
FCRP-D---帆软官网模拟题,kettle模块
NepCTF2022
RENIX_ IPv6 automatic configuration -- practical operation of network tester
随机推荐
NH2-MIL-125 (Ti)/TiO2复合纳米纤维|镧系金属有机骨架([email protected])|mof有机骨架材料
Synthesis route of dansyl fluorescein labeled peptide nucleic acid coupled peptide | dansyl AHX PNA fluorescein labeled peptide nucleic acid
Ctfhub information disclosure
Demystifying Closures, Futures and async-await in Rust–Part 3: Async & Await
PHP-CGI远程代码执行漏洞(CVE-2012-1823)
Solve the problem that the time field is blank when kettle8.2 version table input excel output
2D array theme
工业4.0数字孪生下的应用案例
从新零售到社区团购,这中间发生了多少变化?
Mysql字符集和排序规则
后深度学习时代,推荐系统向何处去?
Excel does not count repeatedly through sumproduct and countifs (the data contains blank cells)
狂神说Es
Find the maximum of 10 integers
2022 dsctf first digital space security attack and defense competition
【IoT毕设.3】STM32单片机+机智云AIoT+猪舍监测与系统硬件设计
技术小百科 | 云原生篇
2022 DSCTF首届数字空间安全攻防大赛
小程序的破局之道,数字化营销已然成为趋势
Getting started with ctfshow web (file upload)