#include <stdio.h>
#include <stdlib.h>
#define N 15
void getnumber(int *s,int x)
{int i;
s[N]=0;
for(i=0;i<N;)
{x=rand()%30;
for(int j=0; j<i;)
{if(s[i] == s[j])
{mark = 1;
break;
}
else
j++;
}
if(mark ==1)
{ mark =0;
continue;
}
else
{i++;
mark =0;
}
}
void arrout(int *s)
{int i;
for(i=0;i<N;i++) printf("%5d",s[i]);
printf("\n");
}
main()
{int x, a[N];
getnumber(a,x);
arrout(a);
system("PAUSE");
return 0;
}
Ps:只正對樓主所編程序作修改!個人覺得不用其他函數調用也可以,比如5樓的程序就很精簡,可讀性高,
#include <stdlib.h>
#define N 15
void getnumber(int *s,int x)
{int i;
s[N]=0;
for(i=0;i<N;)
{x=rand()%30;
for(int j=0; j<i;)
{if(s[i] == s[j])
{mark = 1;
break;
}
else
j++;
}
if(mark ==1)
{ mark =0;
continue;
}
else
{i++;
mark =0;
}
}
void arrout(int *s)
{int i;
for(i=0;i<N;i++) printf("%5d",s[i]);
printf("\n");
}
main()
{int x, a[N];
getnumber(a,x);
arrout(a);
system("PAUSE");
return 0;
}
Ps:只正對樓主所編程序作修改!個人覺得不用其他函數調用也可以,比如5樓的程序就很精簡,可讀性高,