回 帖 发 新 帖 刷新版面

主题:一个问题改成函数调用

起泡法比较10个数的大小。程序如下
   

#include <stdio.h>                                                
void main()                                                        
{
  int[10];                                                         
  inti,j,t;                                                      
  printf("please input 10 numbers\n");                             
   for(i=0;i<10;i++)                                              
      scanf("%d",a[i]);                                             
      printf("\n");                                                
    for(j=0;j<9;j++)                                               
      for(i=0;i<9-j;i++)                                            
        if(a[i]>a[i+1])                                            
          {
            t=a[i];                                                 
             a[i]=a[i+1];                                           
             a[i+1]=t;                                              
           }
        printf("the sorted number \n");                             
    for(i=0;i<10;i++)                                               
        printf("%d",a[i]);                                            
    printf("\n");                                                   
}
                                             哪位高手给改成函数调用的形式。谢了

回复列表 (共2个回复)

沙发

void bubb(int a[],int n) 
{
   for(j=0;j<n-1;j++)                                               
      for(i=0;i<n-j;i++)                                            
        if(a[i]>a[i+1])                                            
          {
            t=a[i];                                                 
             a[i]=a[i+1];                                           
             a[i+1]=t;                                              
           }
        printf("the sorted number \n");                             
    for(i=0;i<n;i++)                                               
        printf("%d",a[i]);                                            
}

板凳

你的输入语句忘加&了

我来回复

您尚未登录,请登录后再回复。点此登录或注册