c語言 for循環語句 if語句
#include
#include
main()
{
int x[28];
int d,d1,d2,d3;
int i,flag;
float sum=0;
for (i=0;isrand((unsigned)time(NULL)); // 每次計算都隨機則要此句
while (1){
d1=rand() % 10; d2=rand() % 10; d3=rand() % 10; // 取3個隨機數
d = d1+d2+d3; // 之和
x[d]=x[d]+1; // 此數個數增1
flag = 1;
for (i=0;iif (flag==1) break; // 成功
}
// 輸出 0-27 各數出現次數
for (i=0;ifor (i=0;iprintf("\n");
// 輸出 0-27 各數出現次數的百分比(概率)
for (i=0;ireturn 0;
}
IF是不是循環語句
if是判斷語句。它的結構一般有以下幾種形式:
一、
if …… then ……
二、
if …… then …… else ……
三、
if …… then
……
else
……
end if
四、
if …… then
……
elseif …… then
……
elseif …… then
……
……
else
……
end if