开发者社区 问答 正文

编写程序:用冒泡排序法对15个浮点数进行排序。这15个浮点数用数组存放.

编写程序:用冒泡排序法对15个浮点数进行排序。这15个浮点数用数组存放.

展开
收起
知与谁同 2018-07-18 09:28:50 5313 分享 版权
2 条回答
写回答
取消 提交回答
  • #include<stdio.h>
    int main(void)
    {
    float bubble[15];
    printf("Enter 15 float numbers:\n");
    for(int i=0;i<15;++i)
    scanf("%f",&bubble[i]);
    for(int k=0;k<14;++k)
    for(int j=k;k<15;++k)
    {
    float temp;
    if(bubble[k]>bubble[j])
    {
    temp=bubble[k];
    bubble[k]=bubble[j];
    bubble[j]=temp;
    }
    }
    for(i=0;i<15;++i)
    printf("%f\n",bubble[i]);
    printf("\n");
    return 0;
    }
    2019-07-17 22:50:41
    赞同 展开评论
  • 这个时候,玄酱是不是应该说点什么...
    以下程序供你参考学习: #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>int main()
    {
    float a[15];
    int i,j;
    printf("Please input 15 float numbers: ");
    for(i=0;i<15;i++)
    {
    scanf("%f",&a[i]);
    }
    for(i=0;i<15;i++)
    {
    for(j=0;j<14-i;j++)
    {
    if(a[j]>a[j+1])
    {
    float t;
    t=a[j];
    a[j]=a[j+1];
    a[j+1]=t;
    }
    }
    }
    printf("The sorted numbers are: ");
    for(i=0;i<15;i++)
    {
    printf("%f ",a[i]);
    }
    printf("\n");
    system("pause");
    return 0;
    }
    2019-07-17 22:50:41
    赞同 展开评论
问答地址: