我是靠谱客的博主 悲凉冰淇淋,这篇文章主要介绍c语言随机数算重复了几次,写了个随机数的程序,太TM长了,而且很多重复语句,谁来帮忙看看...,现在分享给大家,希望可以做个参考。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

写了个随机数的程序,太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语言随机数算重复了几次,写了个随机数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(119)

评论列表共有 0 条评论

立即
投稿
返回
顶部