日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

结构化程序goto语句_C ++ goto语句| 查找输出程序| 套装1

發(fā)布時(shí)間:2025/3/11 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 结构化程序goto语句_C ++ goto语句| 查找输出程序| 套装1 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

結(jié)構(gòu)化程序goto語句

Program 1:

程序1:

#include <iostream> #include <math.h> using namespace std;int main() {int num1 = 1;int num2 = 0;MY_LABEL:num2 = num1 * num1;cout << num2 << " ";num1 = num1 + pow(2, 0);if (num1 <= 5)goto MY_LABEL;return 0; }

Output:

輸出:

1 4 9 16 25

Explanation:

說明:

The above code will print "1 4 9 16 25" on the console screen.

上面的代碼將在控制臺(tái)屏幕上顯示“ 1 4 9 16 25” 。

Understand the program step by step.

逐步了解程序。

Here we initialize the variables num1 and num2 by 1, 0 respectively.? And we created a label MY_LABEL.

在這里,我們分別將變量num1num2初始化為1、0。 然后我們創(chuàng)建了標(biāo)簽MY_LABEL 。

Now evaluate statements iteration wise:

現(xiàn)在,明智地評(píng)估語句迭代:

First iteration:

第一次迭代:

num1=1, num2=0 num2 = num1 * num1; Then num1 = 1 and num2 = 1 and then print num2 that is 1. As we know that if we calculate the zero power of any number that will be 1. num1 = num1 + pow(2,0); Then the above statement will increase the value of num1 by one. Then num1 become 2. And num1 is less than equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.

Second iteration:

第二次迭代:

num1=2, num2=0 num2 = num1 * num1; After execution of above statement, num1=2 and num2=4 and then print num2 that is 4 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 3. And num1 is less then equal to 5 then "goto” statement will transfer the program control to the MY_LABEL.

Third Generation:

第三代:

num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=3 and num2=9 and then print num2 that is 9 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 4. And num1 is less then equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.

Fourth iteration:

第四次迭代:

num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=4 and num2=16 and then print num2 that is 16 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 5. And num1 is less then equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.

Fifth iteration:

第五次迭代:

num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=5 and num2=25 and then print num2 that is 25 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 6. Then condition get false and program get terminated.

Program 2:

程式2:

#include <iostream> #include <math.h> using namespace std;int main() {int num1 = 1;int num2 = 0;int num3 = 1;MY_LABEL:num3 = num3 + num2;cout << num3 << " ";num2 = num2 + 1;num1 = num1 + 1;if (num1 <= 4)goto MY_LABEL;return 0; }

Output:

輸出:

1 2 4 7

Explanation:

說明:

The above code will print "1 2 4 7" on the console screen.

上面的代碼將在控制臺(tái)屏幕上顯示“ 1 2 4 7”

Understand the program step by step.

逐步了解程序。

Here we initialize the variables num1, num2, and num3 by 1, 0, and 1 respectively.? And we created a label MY_LABEL.

在這里,我們分別將變量num1num2num3分別初始化為1、0和1。 然后我們創(chuàng)建了標(biāo)簽MY_LABEL

Now evaluate statements iteration wise:

現(xiàn)在,明智地評(píng)估語句迭代:

First iteration:

第一次迭代:

Here initial values of num1=1, num2 =0, and num3 =1 after executing all statements "1" will be printed on console screen and modified value will be:num1 = 2, num2 = 1, num3= 1;If the condition is true then program control will be transferred to MY_LABEL.

Second iteration:

第二次迭代:

Here values of num1=2, num2 =1, and num3 =1 after executing all statements "2" will be printed on console screen and modified value will be: num1 = 3, num2 = 2, num3= 2;If the condition is true then program control will be transferred to MY_LABEL.

Third iteration:

第三次迭代:

Here values of num1=3, num2 =2, and num3 =2 after executing all statements "4" will be printed on console screen and modified value will be: num1 = 4, num2 = 3, num3= 4;If the condition is true then program control will be transferred to MY_LABEL.

Fourth iteration:

第四次迭代:

Here values of num1=4, num2 =3, and num3 =4 after executing all statements "7” will be printed on console screen and modified value will be: num1 = 4, num2 = 4, num3= 7;Now the if condition gets false and the program will terminate.

Recommended posts

推薦的帖子

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

    C ++ goto語句| 查找輸出程序| 套裝2

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

    C ++運(yùn)算符| 查找輸出程序| 套裝1

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

    C ++運(yùn)算符| 查找輸出程序| 套裝2

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

    C ++ const關(guān)鍵字| 查找輸出程序| 套裝1

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

    C ++ const關(guān)鍵字| 查找輸出程序| 套裝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 ++轉(zhuǎn)換語句| 查找輸出程序| 套裝1

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

    C ++轉(zhuǎn)換語句| 查找輸出程序| 套裝2

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

    C ++循環(huán)| 查找輸出程序| 套裝1

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

    C ++循環(huán)| 查找輸出程序| 套裝2

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

    C ++循環(huán)| 查找輸出程序| 套裝3

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

    C ++循環(huán)| 查找輸出程序| 套裝4

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

    C ++循環(huán)| 查找輸出程序| 套裝5

翻譯自: https://www.includehelp.com/cpp-tutorial/goto-statement-find-output-programs-set-1.aspx

結(jié)構(gòu)化程序goto語句

總結(jié)

以上是生活随笔為你收集整理的结构化程序goto语句_C ++ goto语句| 查找输出程序| 套装1的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。