Created
March 28, 2019 04:37
-
-
Save ruyut/5243a5b639eb4aa840bfa8b05153ba30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//902 | |
#include<stdlib.h> | |
#include<stdio.h> | |
int main() { | |
int i, c[6];//宣告整數,宣告整數陣列 | |
c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 0;//整數陣列設為0 | |
for (i = 0; i<6; i++) {//從0開始到5 會出現0 1 2 3 4 5 共6次 | |
c[i] = rand() % 49 + 1;//整數陣列的第i個等於亂數產生0~48,+1之後變成1~49 | |
while ((c[i] == c[0] && i != 0) || (c[i] == c[1] && i != 1) || (c[i] == c[2] && i != 2) || (c[i] == c[3] && i != 3) || (c[i] == c[4] && i != 4) || (c[i] == c[5] && i != 5)) { | |
//如果整數陣列中第i個等於第0~5個的話 | |
c[i] = rand() % 49 + 1;//產生新的亂數 | |
} | |
} | |
printf("數字: "); | |
for (i = 0; i<6; i++)//從0開始到5,會出現6次 | |
printf("%d ", c[i]);//列印出整數 | |
system("PAUSE");//等待使用者按下任意按鍵 | |
return 0;//跳出 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment