c語言迴圈案例

2021-09-22 13:09:41 字數 1771 閱讀 4642

do while

#include

#include

intmain

() while

(b-- < 0);

printf("%d\n"

,b); // 8

return

0;}

不管條件是否滿足都執行一次。

模擬dos遊戲。

#include

#include

intmain

() } while

(choice <1 || choice > 3);

switch

(choice)

return

0;}

迴圈實現數字反轉

#include

#include

intmain

() } while

(value <= 0);

printf ("

\n反轉後的數為:"

); do

while

(value != 0);

printf("\n"

); return

0;}

列印加法表

printf("遊戲結束!"

() printf("錯誤的次數為%d"

,wrongcount);

return

0;}

#include

#include

intmain

() }

printf("1到100之間的偶數和為%d"

,sum);

return

0;}

#include

#include

intmain

() else

for(j = 0;j < spacenum; j++)

for(j = 0;j < starnum; j++)

printf("\n"

); }

return

0;}

c語言迴圈案例

do while include include int main while b 0 printf d n b 8 return 0 不管條件是否滿足都執行一次。模擬dos遊戲。include include int main while choice 1 choice 3 switch choi...

C語言案例

1.水仙花數code include int main void printf 100 999有 d個水仙花數 count 2.兩個時間只差 include int main void if year1 year2 if month1 month2 第一年的是這年的多少天 switch month1...

C語言for迴圈

c語言中的 for語句使用最為靈活,它完全可以替代 while 語句。for 表示式 1 表示式 2 表示式 3 語句 執行過程 1 求解表示式1 2 求解表示式2 若值為真 非 0 則執行 for語句中的內嵌語句,然後執行第 3不,若值未加,結束迴圈,執行5部 3 求解表示式3 4 轉回2 步驟繼...