它應該是一個乘法表,x 軸上從 1 到 6,y 軸上從 1 到 5,所以我有這個 if 陳述句,一旦乘法達到 6,它應該跳到 nezt 行,但它甚至會繼續執行盡管我重置了其中要滿足的條件。
#include <stdio.h>
#include <stdlib.h>
int main(){
int mult = 1;
int check = 0;
int res;
while(mult != 6){
if (check <= 6){
res = mult * check;
printf("%d ",res);
check ;
}
if (check > 6 ){
printf("\n ");
check = 0;
}
}}
uj5u.com熱心網友回復:
該if陳述句使您執行或不執行塊。
例如,在您的代碼中:
if (check <= 6){
res = mult * check;
printf("%d ",res);
check ;
}
if (check > 6 ){
printf("\n ");
int check = 0;
}
第一個塊將在 時執行check <= 6,第二個塊將用check > 6...執行,但while回圈中的條件是mult != 5... 并且您永遠不會修改mult,因此條件始終為真。
因此,除了 uZuMaKioBaRuTo 對您的check變數的評論之外,您還需要增加mult:
if (check > 6 ){
printf("\n ");
check = 0;
mult ;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/343427.html
上一篇:僅在用戶輸入憑據時才添加登錄按鈕
下一篇:如何在React中動態命名變數
