概述
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
写了个随机数的程序,太TM长了,而且很多重复语句,谁来帮忙看看帮我简化下。。。我不行啊。。。谢了。。。
能运行,就是长得离谱,有没有简化版呢?
#include
#include
#include
int main (void)
{
int i, n, a, b;
char ch;
printf("In which interval do you want the number to lie in? [a,b]n");
printf("Please type two integers(the second number must be larger or equal to the first one)n");
printf("a=");
scanf("%d", &a);
printf("b=");
scanf("%d", &b);
printf("n");
if (a>b)
{
printf("You numbers are not appropriate.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
while (ch=='Y'||ch=='y')
{
printf("nPlease type two integers(the second number must be larger or equal to the first one)n");
printf("a=");
scanf("%d", &a);
printf("b=");
scanf("%d", &b);
printf("n");
if (a>b)
{
printf("You numbers are not appropriate.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
}
else
{
printf("So the interval you want is [%d,%d]n", a, b);
printf("How many integers do you want?n");
scanf("%d", &n);
srand(time(NULL));
if (n<=0)
{
printf("You will not get any integers unless you type a positive integer.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
while (ch=='Y'||ch=='y')
{
printf("nHow many integers do you want?n");
scanf("%d", &n);
if (n<=0)
{
printf("nYou will not get any integers unless you type a positive integer.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
}
else
{
for (i=1; i<=n; i++)
printf("%dt",rand()%(b-a+1)+a);
printf("n");
ch='c';
}
}
}
else
{
for (i=1; i<=n; i++)
printf("%dt",rand()%(b-a+1)+a);
printf("n");
}
}
}
}
else
{
printf("So the interval you want is [%d,%d]n", a, b);
printf("nHow many integers do you want?n");
scanf("%d", &n);
srand(time(NULL));
if (n<=0)
{
printf("nYou will not get any integers unless you type a positive integer.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
while (ch=='Y'||ch=='y')
{
printf("How many integers do you want?n");
scanf("%d", &n);
if (n<=0)
{
printf("You will not get any integers unless you type a positive integer.n");
printf("Would you like to type again? (Y/N)n");
scanf(" %c", &ch);
}
else
{
for (i=1; i<=n; i++)
printf("%dt",rand()%(b-a+1)+a);
printf("n");
ch='c';
}
}
}
else
{
for (i=1; i<=n; i++)
printf("%dt",rand()%(b-a+1)+a);
printf("n");
}
}
return 0;
}
最后
以上就是悲凉冰淇淋为你收集整理的c语言随机数算重复了几次,写了个随机数的程序,太TM长了,而且很多重复语句,谁来帮忙看看...的全部内容,希望文章能够帮你解决c语言随机数算重复了几次,写了个随机数的程序,太TM长了,而且很多重复语句,谁来帮忙看看...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复