数组插入且排序

一剑行天下 posted @ 2008年11月01日 23:32 in 一般程序 , 1410 阅读

 

#include<stdio.h>
main()
{
        int a[11]={1,4,6,9,13,16,45,457,486,910};
        int i,j,t1,t2,n;
        for(i=0;i<10;i++)
        printf("%6d",a[i]);
        printf("\ninput the number you want to insert:");
        scanf("%d",&n);
        if (a[9]<n)
                a[10]=n;
        else
        {
                for(j=0;j<10;j++)
                {
                        if(a[j]>n)
                        {
                                t1=a[j];
                                a[j]=n;
                                for(i=j+1;i<11;i++)
                                {
                                        t2=a[i];
                                        a[i]=t1;
                                        t1=t2;
                               
                               
                                }
                                break;

                        }
                       
   
                }
       
       
        }
        printf("now print the new datas\n ");
        for(i=0;i<11;i++)
        printf("%6d",a[i]);



}
 

Avatar_small
idolnetworth 说:
2024年3月21日 21:55

If you are interested in your favorite actors' heights and other detailed information, please take a look at celebrity net worth database.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter