多线程循环输出abcc++

Program 1:

程序1:

#include <iostream>
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 <iostream>
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=0
R = 1*0
R = 0
Then I=2 and D=1 and loop condition is true.
Iteration 2:
I=2, D=1, R=0
R = 2*1
R = 2
Then I=3 and D=2 and loop condition is true.
Iteration 3:
I=3, D=2, R=2
R = 3*2
R = 6
Then I=4 and D=3 and loop condition is true.
Iteration 4:
I=4, D=3, R=6
R = 4*3
R = 12
Then I=5 and D=4 and loop condition is true.
Iteration 5:
I=5, D=4, R=12
R = 5*4
R = 20
Then I=6 and D=5 and loop condition is false.
And program terminates.

Program 3:

程式3:

#include <iostream>
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=0
R = 1 * 1
R = 1
Print 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=1
R = 2 * 2
R = 4
But 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=4
R = 3 * 3
R = 9
Print 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=9
R = 4 * 4
R = 16
Print 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=16
R = 5 * 5
R = 25
Print 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

推荐的帖子

  • C++ Looping | Find output programs | Set 1

    C ++循环| 查找输出程序| 套装1

  • C++ Looping | Find output programs | Set 2

    C ++循环| 查找输出程序| 套装2

  • C++ Looping | Find output programs | Set 3

    C ++循环| 查找输出程序| 套装3

  • C++ Looping | Find output programs | Set 4

    C ++循环| 查找输出程序| 套装4

  • C++ Operators | Find output programs | Set 1

    C ++运算符| 查找输出程序| 套装1

  • C++ Operators | Find output programs | Set 2

    C ++运算符| 查找输出程序| 套装2

  • C++ const Keyword | Find output programs | Set 1

    C ++ const关键字| 查找输出程序| 套装1

  • C++ const Keyword | Find output programs | Set 2

    C ++ const关键字| 查找输出程序| 套装2

  • C++ Reference Variable| Find output programs | Set 1

    C ++参考变量| 查找输出程序| 套装1

  • C++ Reference Variable| Find output programs | Set 2

    C ++参考变量| 查找输出程序| 套装2

  • C++ Conditional Statements | Find output programs | Set 1

    C ++条件语句| 查找输出程序| 套装1

  • C++ Conditional Statements | Find output programs | Set 2

    C ++条件语句| 查找输出程序| 套装2

  • C++ Switch Statement | Find output programs | Set 1

    C ++转换语句| 查找输出程序| 套装1

  • C++ Switch Statement | Find output programs | Set 2

    C ++转换语句| 查找输出程序| 套装2

  • C++ goto Statement | Find output programs | Set 1

    C ++ goto语句| 查找输出程序| 套装1

  • C++ goto Statement | Find output programs | Set 2

    C ++ goto语句| 查找输出程序| 套装2

翻译自: https://www.includehelp.com/cpp-tutorial/looping-find-output-programs-set-5.aspx

多线程循环输出abcc++

多线程循环输出abcc++_C ++循环| 查找输出程序| 套装5相关推荐

  1. 多线程循环输出abcc++_C ++循环| 查找输出程序| 套装4

    多线程循环输出abcc++ Program 1: 程序1: #include <iostream> using namespace std; int A = 5; int fun() { ...

  2. 多线程循环输出abcc++_C ++循环| 查找输出程序| 套装2

    多线程循环输出abcc++ Program 1: 程序1: #include<iostream> using namespace std; int main() { for(;;) { c ...

  3. c ++查找字符串_C ++数组| 查找输出程序| 套装5

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { char* STR[] = ...

  4. c ++查找字符串_C ++结构| 查找输出程序| 套装2

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { typedef struct ...

  5. c ++查找字符串_C ++结构| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> #include <math.h> using namespace std; str ...

  6. c ++查找字符串_C ++异常处理| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { try { int num1 ...

  7. c ++查找字符串_C ++结构| 查找输出程序| 套装3

    c ++查找字符串 Program 1: 程序1: #include <iostream> #pragma pack(1) using namespace std; typedef str ...

  8. c ++ 继承_C ++继承| 查找输出程序| 套装1

    c ++ 继承 Program 1: 程序1: #include <iostream> #include <string.h> using namespace std; cla ...

  9. c ++查找字符串_C ++类和对象| 查找输出程序| 套装4

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...

最新文章

  1. Java中的多线程编程(超详细总结)
  2. 如何快速上手mysql_如何快速上手数据库操作?
  3. NullPointerException
  4. Java8 Collections.sort()及Arrays.sort()中Lambda表达式及增强版Comparator的使用
  5. QQ病毒越来越人性化了
  6. WebSocket 实现前后端通信的笔记
  7. grubbs检测c语言,Grubbs算法检测离群值
  8. 打造大数据和AI能力底座 联通大数据深度参与“新基建”
  9. 红黑树 —— 原理和算法详细介绍
  10. C51单片机——指令系统
  11. python视频处理加速的库_VPF:适用于 Python 的开源视频处理框架,加速视频任务、提高 GPU 利用率...
  12. 2017 ACM/ICPC Asia Regional Beijing Online 记录
  13. c语言的常用英语单词和翻译,c语言通用英语词汇带翻译
  14. 计算LED分压电阻时?需要注意哪些事情?
  15. java日期计算天数_Java 两个日期间的天数计算
  16. iOS NSString,NSLog添加%百分号和引号等符号
  17. 2020年3月20日阿里内推笔试题
  18. Windows7下新建记事本的四种编码方式
  19. uefi怎么念_uefi和legacy是什么意思
  20. messagrbox自定义按钮c语言,基于dialogbox修改可自定义按钮及事件的弹出框插件

热门文章

  1. 超大规模集成电路_纳米级超大规模集成电路芯片低功耗物理设计分析(二)
  2. vue企业网站模板_模板网站VS定制网站,企业如何选择?
  3. Copy-On-Write COW机制
  4. HDL的综合和c语言的编译区别,C语言与verilog 的区别及相互转化
  5. python pip使用_Python——pip的安装与使用
  6. ios 不被遮挡 阴影_IOS开发之Bug--iOS7View被导航栏遮挡问题的解决
  7. dev 中 gridcontrol1 滚动条重绘_浏览器的重绘和回流(Repaint amp; Reflow)
  8. LDAP----manage-account
  9. linux tips 技巧笔记一
  10. MySQL为什么要set names