当前位置: 首页 > news >正文

第4章 程序段的反复执行4.2while语句P128练习题(题及答案)

((1)阅读程序

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main(){int n,s=0;cin >> n;while(n){s = s * 10 + n % 10;n /= 10;}cout << s << endl;return 0;
}

分别输入:0 1024 1234567890

输出结果:0 4201 987654321

((2)阅读程序

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main(){int n;cin >> n;while(n != 0){cout << n % 2;n /= 2;}return 0;
}

输输入: 4 0

输输出:001 无输出

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main(){int n,sum = 0;cin >> n;while(n){sum += n % 10;n /= 10;} cout << sum << endl;return 0;
}

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main() {int n, m, i, j;cin >> n >> m;i = n;j = m;while(i != j) {if(i > j)i -= j;elsej -= i;}if(i == 1)cout << "Yes";elsecout << "No";return 0;
}

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main(){int l,r,ans = 0;cin >> l >> r;for(int i = l;i <= r; i++){//拆位int x = i;while(x){int c = x % 10;if(c == 2) ans++;x /= 10;} }cout << ans << endl;return 0;
}

#include <bits/stdc++.h>
using namespace std;
//汤永红
int main() {int n, K;double Sn, An;printf("Please input K(1<=K<=15):");scanf("%d", &K);if ((K >= 1) && (K <= 15)) {n = 1;while(1) {An = 1.0 / n;Sn += An;if (Sn > K) {break;}n++;}printf("n=%d,Sn=%f\n", n, Sn);} else {printf("Input error!Please input again!\n");}return 0;
}

I(2016)love(08)China(15)!
L(2016)oryh(08)Fklqd(15)!
#include <bits/stdc++.h>
using namespace std;
//汤永红
char c;
int main() {while((c = getchar() ) != '\n') {if(islower(c)) {putchar('a' + (c - 'a' + 3) % 26);} else if(isupper(c)) {putchar('A' + (c - 'A' + 3) % 26);} else {putchar(c);}}return 0;
}

http://www.lryc.cn/news/614805.html

相关文章:

  • ppt 生成视频的 ai 大模型全面解析
  • (talk)西安大模型开发者talk
  • vue+flask大模型写诗诗词推荐与可视化系统
  • 浏览器面试题及详细答案 88道(01-11)
  • 项目一系列-第4章 在线接口文档 代码模板改造
  • AJAX与axios框架
  • Netty-Rest搭建笔记
  • 系统集成项目管理工程师【第十一章 规划过程组】规划成本管理、成本估算、制定预算和规划质量管理篇
  • 轻松实现浏览器自动化——AI浏览器自动化框架Stagehand
  • 【华为机试】63. 不同路径 II
  • C++简单项目跟练【通讯录管理系统000】
  • 数据集: TSPLIB旅行商问题-对称TSP数据集
  • 宁商平台税务升级之路:合规为纲,服务为本
  • 五、SpringBoot工程打包与运行
  • 解决 MinIO 上传文件时报 S3 API Requests must be made to API port错误
  • Sklearn 机器学习 数据降维PCA 使用PCA算法
  • Java 之 设计模式
  • Python day38
  • SVM算法实战应用
  • 【感知机】感知机(perceptron)学习算法例题及详解
  • 政治社会时间线
  • 为什么输入 URL 后会显示页面?HTTP 协议的 “幕后操作”
  • JDK、eclipse的安装,配置JDK、Tomcat并使用eclipse创建项目
  • Cursor CLI 来了,准备 Build anything
  • latex基础
  • Vue 路由跳转
  • Redis数据组织方式
  • 第39周——训练自己的数据集
  • Vue 组件化开发
  • 零基础小白如何使用QGIS制作研究区地形区位图教程