作业帮 > 综合 > 作业

c语言 编写产生100个1到10范围内的随机数的程序,并且以降序排序

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/02 14:18:21
c语言 编写产生100个1到10范围内的随机数的程序,并且以降序排序
c语言 编写产生100个1到10范围内的随机数的程序,并且以降序排序
#include
#include
int main()
{
\x09int i,j;
\x09unsigned seed;
\x09int a[101];
\x09printf("please input seed");
\x09scanf("%d",&seed);
\x09srand(seed);
\x09for(i = 0; i < 100; i++)
\x09\x09a[i] = rand() % 10 +1;
\x09for(i = 0; i < 100 ; i++)
\x09\x09for(j = i+1; j < 100; j++)
\x09\x09{
\x09\x09\x09if(a[i]>a[j])
\x09\x09\x09{
\x09\x09\x09\x09int temp = a[i];
\x09\x09\x09\x09a[i] = a[j];
\x09\x09\x09\x09a[j] = temp;
\x09\x09\x09}
\x09\x09}
\x09for(i = 0;i < 100; i++)
\x09\x09printf("%d\t",a[i]);
\x09printf("\n");
\x09return 0;
}