#include<stdio.h>
#include<stdlib.h>
void fn(int i)
{
int a,b,c,d,e,f;
static int k=0;
k=k+1;
if(k==5000) exit(0);//防止无限循环导致内存出错,这里只循环5000次
a=rand()%33+1;
b=rand()%33+1;
c=rand()%33+1;
d=rand()%33+1;
e=rand()%33+1;
f=rand()%33+1;
if((a+b+c+d+e+f)==i)
printf("产生6个随机为%5d%5d%5d%5d%5d%5d\n",a,b,c,d,e,f);
else
fn(i);
}
int main()
{
int m;
printf("请输出你要数");
scanf("%d",&m);
while(m>198||m<6)
{
printf("你输入的数不符合要求,请重新输入");
scanf("%d",&m);
}
fn(m);
return 0;
}
[
本帖最后由 hziee 于 2010-3-22 20:10 编辑 ]