博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多线程循环输出abcc++_C ++循环| 查找输出程序| 套装5
阅读量:2530 次
发布时间:2019-05-11

本文共 2909 字,大约阅读时间需要 9 分钟。

多线程循环输出abcc++

Program 1:

程序1:

#include 
using namespace std;int main(){ int num = 15673; int R1 = 0, R2 = 0; do { R1 = num % 10; R2 = R2 * 10 + R1; num = num / 10; } while (num > 0); cout << R2 << " "; return 0;}

Output:

输出:

37651

Explanation:

说明:

Here, we declared three local variables num, R1, and R2, and we are calculating the reverse of variable num, and R1 is used to extract the last digit in each iteration and R2 to store the result.

在这里,我们声明了三个局部变量numR1R2 ,并且正在计算变量num的倒数,并且R1用于提取每次迭代的最后一位, R2用于存储结果。

Iteration 1:num=15673, R1=0, R2=0.After executing loop statements R1=3, R2=3, and num=1567.Iteration 2:num=1567, R1=3, R2=3.After executing loop statements R1=7, R2=37, and num=156.Iteration 3:num=156, R1=6, R2=37.After executing loop statements R1=6, R2=376, and num=15.Iteration 4:num=15, R1=5, R2=376.After executing loop statements R1=5, R2=3765, and num=1.Iteration 5:num=1, R1=1, R2=3765.After executing loop statements R1=1, R2=37651 and num=0.Then the condition will false and print "37651"

Program 2:

程式2:

#include 
using namespace std;int main(){ int I = 1; int D = 0; int R = 0; do { R = I++ * D++; cout << R << " "; } while (I <= 5); return 0;}

Output:

输出:

0 2 6 12 20

Explanation:

说明:

In the above program, we declared three local variables I, D, and R.

在上面的程序中,我们声明了三个局部变量IDR。

Iteration 1:I=1, D=0, R=0R = 1*0R = 0Then I=2 and D=1 and loop condition is true. Iteration 2:I=2, D=1, R=0R = 2*1R = 2Then I=3 and D=2 and loop condition is true.Iteration 3:I=3, D=2, R=2R = 3*2R = 6Then I=4 and D=3 and loop condition is true.Iteration 4:I=4, D=3, R=6R = 4*3R = 12Then I=5 and D=4 and loop condition is true.Iteration 5:I=5, D=4, R=12R = 5*4R = 20Then I=6 and D=5 and loop condition is false. And program terminates.

Program 3:

程式3:

#include 
using namespace std;int main(){ int I = 1; int D = 1; int R = 0; do { R = I++ * D++; if (I == 3) continue; cout << R << " "; } while (I <= 5); return 0;}

Output:

输出:

1 9 16 25

Explanation:

说明:

In the above program, we declared three local variables I, D, and R.

在上面的程序中,我们声明了三个局部变量IDR。

Iteration 1:I=1, D=1, R=0R = 1 * 1R = 1Print the value of R that is 1.Then I=2 and D=2 and loop condition is true. Iteration 2:I=2, D=2, R=1R = 2 * 2R = 4But it will skip "cout" statement because of the continue statement.Then I=3 and D=3 and loop condition is true. Iteration 3:I=3, D=3, R=4R = 3 * 3R = 9Print the value of R that is 9.Then I=4 and D=4 and loop condition is true. Iteration 4:I=4, D=4, R=9R = 4 * 4R = 16Print the value of R that is 16.Then I=5 and D=5 and loop condition is true. Iteration 5:I=5, D=5, R=16R = 5 * 5R = 25Print the value of R that is 25.Then I=6 and D=6 and loop condition is false. Then the loop will terminate.

Recommended posts

推荐的帖子

翻译自:

多线程循环输出abcc++

转载地址:http://notzd.baihongyu.com/

你可能感兴趣的文章
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>
kibana的query string syntax 笔记
查看>>
旋转变换(一)旋转矩阵
查看>>
thinkphp3.2.3 bug集锦
查看>>
[BZOJ 4010] 菜肴制作
查看>>
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>
VsVim - Shortcut Key (快捷键)
查看>>
C++练习 | 模板与泛式编程练习(1)
查看>>
HDU5447 Good Numbers
查看>>
08.CXF发布WebService(Java项目)
查看>>
java-集合框架
查看>>
RTMP
查看>>
求一个数的整数次方
查看>>
点云PCL中小细节
查看>>