gpt4 book ai didi

c - printf 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:13 25 4
gpt4 key购买 nike

这段 C 代码应该创建一些随机数并打印它们,然后对它们进行排序并再次打印它们,但它只打印排序后的数字。任何人都可以帮助我吗?

    #include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
int i, j, k;
float temper;
time_t t;
float grades[1000];
fflush(stdout);
printf("Here are the number\n");
srand(time(&t));
for(i=0;i<1000;i++){
grades[i]=rand();
printf("%f\n", grades[i]);
}
for(i=0;i<1000;i++){
int swap=0;
for(j=i;j<1000;j++){
if(grades[i]>grades[j]){
temper=grades[i];
grades[i]=grades[j];
grades[j]=temper;
swap=1;
}
}
}
printf("sorting is done");
for(i=0;i<1000;i++){
printf("%f\n", grades[i]);
} }

最佳答案

您的程序运行正常。尝试将所有值从 1000 更改为 10,以便自己测试和查看。

发生的事情是,它打印所有内容的速度如此之快,以至于前 1000 个都从页面上消失了。

关于c - printf 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com