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

第4章 程序段的反复执行2 while语句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.dtcms.com/a/323751.html

相关文章:

  • 2025AI颠覆认知!解锁智能新纪元
  • Kubernetes 无法识别你定义的 `CronJob` 资源*逐步解决方案
  • AI推理的“灵魂五问”:直面2025算力鸿沟与中国的破局之路
  • PowerShell 入门系列(五):运行命令与命令剖析详解
  • 面试题-----Spring Cloud
  • n8n 入门指南:更适合跨境出海搞钱的AI智能体
  • 7天精通Coze智能体实操手册(Day 1)
  • 健全性测试(Sanity Testing):你软件的快速“体检” ✅(省时避坑,确保核心!)
  • 【三个数绝对值排序】2022-10-10
  • 心灵笔记:思考三部曲
  • 记忆化搜索@cache与自己创建一个字典进行存储有区别吗
  • 10.final, finally, finalize的区别
  • Level-MC 11“天空”
  • SpringBoot配置生效优先级
  • 实战:MyBatis 中 db.properties 的正确配置与最佳实践
  • 通过 SCP 和 LXD 配置迁移 CUDA 环境至共享(笔记)
  • HTML全景效果实现
  • C语言(长期更新)第9讲:操作符详解(一)
  • 《励曼旋耕》Liman Rotary Tillage
  • AI大模型模态特征详解
  • 功能测试中常见的面试题-一
  • 第4章 程序段的反复执行for语句P115练习题(题及答案)
  • C++面向对象及其特性
  • 大语言模型提示工程与应用:大语言模型进阶提示工程技术
  • 【LLM实战|langchain】langchain基础
  • 百度网盘自动启动如何关闭,关闭智能看图
  • Windows系统NUL文件删除问题解决
  • 【ref、toRef、toRefs、reactive】
  • C++学习之STL学习:map/set
  • openvela之ADB