作业帮 > 数学 > 作业

有几个固定的整数(不重复)和一个随机整数 求比这个随机数大或相等的最小整数值.望高手赐教程序设计算法

来源:学生作业帮 编辑:作业帮 分类:数学作业 时间:2024/07/03 08:52:47
有几个固定的整数(不重复)和一个随机整数 求比这个随机数大或相等的最小整数值.望高手赐教程序设计算法
例:固定的整数为10,17,38,209,333.
随机整数为88.
在这个固定的整数中比随机数大的最小整数为209
随机数为232
这个随机数不等于5个固定数中的任何一个
比这个随机数大的最小整数值为333
Press any key to continue
#include
#include
#include
main()
{
int randnum,arry[5]={10,17,38,209,333};
srand((unsigned)time(NULL));
randnum = rand()%400;
printf("随机数为%d\n",randnum);
printf("这个随机数等于");
switch (randnum)
{
case 10:printf("%d\n",arry[0]);
break;
case 17:printf("%d\n",arry[1]);
break;
case 38:printf("%d\n",arry[2]);
break;
case 209:printf("%d\n",arry[3]);
break;
case 333:printf("%d\n",arry[4]);
break;
default:printf("这个随机数不等于5个固定数中的任何一个\n");
}
if (randnum>arry[0] && randnumarry[1] && randnumarry[2] && randnumarry[3] && randnumarry[4] )
{
printf("大于最大固定数\n");
}else
printf("小于最小固定数\n");
}