如何改下面的代碼rand 輸出 Y 或 N
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
main()
{
srand((int)time(0));
for(int x=0;x<10;x++)
printf("%d\n",random(100));
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
main()
{
srand((int)time(0));
for(int x=0;x<10;x++)
printf("%d\n",random(100));
}
2018-11-12
舉報
2019-10-20
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char random(int x)
{
????if (rand() % x)
????????return 'y';
????else
????????return 'n';
}
int main()
{
????srand((int)time(0));
????for (int i = 0; i < 10; i++)
????????printf("%c\n", random(2));
????return 0;
}
這樣也可以
2019-10-20
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)
int main()
{
????srand((int)time(0));
????for (int i = 0; i < 10; i++)
????????if(random(2))
????????????printf("%c\n", 'y');
????????else
????????????printf("%c\n", 'n');
????return 0;
}
2019-10-20
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%2)
int main()
{
????srand((int)time(0));
????for (int i = 0; i < 10; i++)
????????if(random(100))
????????????printf("%c\n", 'y');
????????else
????????????printf("%c\n", 'n');
????return 0;
}
2018-11-12
天哪,完全看不明白你的問題,程序也看不明白。。。。。。