Demo entry 6359413

实验一

   

Submitted by 实验一 on Apr 28, 2017 at 09:02
Language: C. Code size: 2.5 kB.

#include <stdio.h>
void xianshi(int su[],int leg)        //ÏÔʾÊý×éÖеÄÔªËغ¯Êý£¬legΪҪÏÔʾµÄÊý×éµÄ³¤¶È
{   int i=0;
    for(i=0;i<leg;i++)
       {
       printf("%d\t",su[i]);
       }
        printf("\n");
}
void paixu(int su[],int leg)          //ðÅÝ·¨ÅÅÐòº¯Êý
{
    int t=leg;int c=0;int i=0;int j=0;
    for(i=0;i<leg;i++)
    {
        for(j=0;j<t-i;j++)
        {
            if(su[j]>su[j+1])
            {
                c=su[j];su[j]=su[j+1];su[j+1]=c;
            }

        }
    }
}
void charu(int su[],int leg)         //²åÈëÔªËغ¯Êý
{   int x;int i=0;
    printf("ÇëÊäÈëÒª²åÈëµÄÔªËØ\n");
    scanf("%d",&x);
    for(i=0;i<leg;i++)
    {
       if(su[i]>x)               //Òª²åÈëµÄÔªËØÒÀ´ÎÓëÓÐÐò±íÖÐÔªËØ˳Ðò±È½Ï£¬ÕÒµ½Òª²åÈëµÄλÖÃ
       { int d;
           for(d=leg-1;d>i-1;d--)//ÕÒµ½¸Ã²åÈëµÄλÖ㬴Ó×îºóÒ»¸öÔªËØ¿ªÊ¼£¬ÒÀ´ÎÏòºóÒƶ¯Ò»Î»£¬Ö±µ½Òƶ¯µ½Òª²åÈëµÄλÖÃ
           {
               su[d+1]=su[d];
           }
           su[i]=x;              //½«Òª²åÈëµÄÔªËزåÈëµ½ÕÒµ½µÄλÖÃÉÏÈ¥
           break;
       }
    }


}
int shanchu(int su[],int leg)    //ɾ³ýÔªËغ¯Êý£¬¿ÉÒÔɾ³ýËùÓÐÖظ´ÔªËØ
{   int x;int i=0;int nu=0;      //nuΪɾ³ýÔªËصĸöÊý
    printf("ÇëÊäÈëҪɾ³ýµÄÔªËØ\n");
    scanf("%d",&x);
    for(i=0;i<leg;i++)
    {
       if(su[i]==x)              //ÕÒµ½ÒªÉ¾³ýµÄÔªËØλÖÃ
       { int d;
           for(d=i;d<leg-1;d++)  //´ÓҪɾ³ýµÄλÖÿªÊ¼£¬½«ºóÃæµÄÔªËØÒÀ´ÎÇ°ÒÆһλ£¬Ö±µ½×îºóÒ»¸öÔªËØ
           {
               su[d]=su[d+1];
           }
           leg--;i--;nu++;       //ɾ³ýÒ»¸öÔªËغó½«Êý×鳤¶È¼õÒ»£¬É¾³ýÔªËظöÊý¼ÓÒ»£¬µ±Ç°Ö¸ÕëλÖÃ"i"Òª¼õÒ»£¬±£Ö¤¿ÉÒÔɾ³ýÖظ´ÔªËØ¡£


       }
    }
return nu;                      //·µ»Øɾ³ýÁ˵ÄÔªËصĸöÊý

}
void main()
{
       int shuzu[15];
       int length=0;             //´æ´¢Êý×éÖÐÔªËصĸöÊý
       printf("ÇëÊäÈë10¸öÔªËØ£¬ÔªËؼäÒÔ¿Õ¸ñ·Ö¿ª \n");
       int m=0;
       for(m=0;m<10;m++)
       {
           scanf("%d",&shuzu[m]);
       }
       length=10;
       paixu(shuzu,length);     //ÅÅÐòº¯Êý
       xianshi(shuzu,length);   //ÏÔʾº¯Êý
       charu(shuzu,length);     //²åÈ뺯Êý
       length=length+1;         //²åÈëºóÔªËظöÊý¼ÓÒ»
       printf("²åÈëºóÅÅÐò\n");
       xianshi(shuzu,length);
       int denu=shanchu(shuzu,length);//ɾ³ýº¯Êý£¬²¢·µ»Øɾ³ýÔªËصĸöÊý
       if(denu==0){printf("¸ÃÔªËز»´æÔÚ\n");}
       length=length-denu;
       printf("ɾ³ýºóÅÅÐò\n");
       xianshi(shuzu,length);



}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).