# 冒泡排序,该如何处理

www.MyException.Cn  网友分享于：2013-03-15  浏览：1次

main()
{int   a[6]={9,8,5,4,2,0};
int   i,j,t;
printf( "the   numbers   is:\n ");
printf( "\n ");
for   (j=1;j <=5;j++)
for(i=1;i <=6-j;i++)
if(a[1]> a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
printf( "the   sorted   number:\n ");
for   (i=1;i <7;i++)
printf( "%d ",a[i]);
}

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
#include <iostream>
int main()
{int a[6]={9,8,5,4,2,0};
int i,j,t;
printf( "the numbers is:\n ");
printf( "\n ");
for (j=1;j <=5;j++)
for(i=1;i <=6-j;i++)
if(a[1]> a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
printf( "the sorted number:\n ");
for (i=1;i <7;i++)
printf( "%d ",a[i]);
return 1;
}
------解决方案--------------------

------解决方案--------------------

if(a[1]> a[i+1])
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

clean完了以后再build试试
------解决方案--------------------
#include <stdio.h> -----> 包含头文件
main()
{int a[6]={9,8,5,4,2,0};
int i,j,t;
printf( "the numbers is:\n "); // 这句想干吗？输出原来的?下面也没看见输出语句的
printf( "\n ");
for (j=1;j <=5;j++)
for(i=1;i <=6-j;i++) // for( i = 0; i < 5; i++ )
if(a[1]> a[i+1]) 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=1;i <7;i++) // for( i = 0; i < 6; i++ ) 数组下标都是从0开始的
printf( "%d ",a[i]);
}
------解决方案--------------------

Options > Directories > Include Directories
Library Directories
Turbo C Directories

------解决方案--------------------
TURBO C的路径设置问题,去网上下个DEV-C++ 这个不错的编译器
------解决方案--------------------