开发者社区> 问答> 正文

使用冒泡排序法,让用户输入10个数字,并按从小到大顺序排序后输出

使用冒泡排序法,让用户输入10个数字,并按从小到大顺序排序后输出

展开
收起
知与谁同 2018-07-21 16:54:55 3468 0
1 条回答
写回答
取消 提交回答
  • Nothing for nothing.
    给,已经编译运行确认了:
    #include<conio.h>
    #include<stdio.h>

    void main()
    {
    int a[10]={NULL};
    int i,j,temp;

    printf("please input the number:\n");
    for(i=0;i<10;i++)
    {
    printf("%d: ",i+1);
    fflush(stdin);
    scanf("%d",&a[i]);
    }

    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    if(a[i]<a[j])
    {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
    }

    printf("After Sort: \n");

    for(i=0;i<10;i++)
    printf("%d ",a[i]);

    getch();
    }
    2019-07-17 22:50:26
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载