为了账号安全,请及时绑定邮箱和手机立即绑定

从数组中插入一个数

从数组中插入一个数

C
qq_四乐_0 2015-10-14 20:28:19
#include<stdio.h>int main(){     int a[6]={2,4,6,8,10};     int i,j,k;         printf ("输入一个数:");     scanf ("%d",&k);     printf("原来的数组:\n");     for(i=0;i<=4;i++)     {     printf("%d\t",a[i]);     }     printf("\n");     for(i=0;i<=3;i++)     {                 if(k>a[i]&&k<a[i+1])          {                         for(j=5;j>i+1;j--)                     {                                 a[j]=a[j-1];                     }                     a[i+1]=k;         }                 else                 {                 if(k<a[0])                 {                         for(j=5;j>i;j--)                        {                             a[j]=a[j-1];                         }                         a[0]=k;                 }                 else if(k>a[4])                 a[5]=k;                     else if(k==a[i])                     {                                 for(j=5;j>i;j--)                      {                                     a[j]=a[j-1];                         }                             a[i]=k;                     }                 }         }             printf("现在的数组:\n");             for(i=0;i<=5;i++)         {                     printf("%d\t",a[i]);         }         return 0;}已知一个由小到大的数组,插入一个数要求按原来规则排序。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1650 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信