標籤
- C
- android
- Objective-c
- Sort
- BlueTooth
- Python
- 133
- Apache
- ArrayList
- BluetoothChat
- C sharp
- C#
- CVS
- CheckBox
- Closest Pair
- Console.ReadLine
- HashMap
- NFC
- NSDocumentDirectory
- NSString
- Pandaboard
- SQLite
- UIAlertController
- VB
- Xcode6
- driver
- execSQL
- gatt error
- httpd.conf
- office
- primie check
- property
- sharedApplication
- 小小問題
2010年12月4日 星期六
[C] Bubble Sort
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=0, j=0;
float grade[8]={63.5,74.2,58.7,91.3,68.2,85.7,39.9,78.5};
float tmp;
printf( "before sort : ");
for(i=0;i<8;i++)
{
printf("%.1f ",grade[i]);
}
printf("\n");
for(i=0;i<8;i++)
{
for(j=0;j<7;j++)
{
if( grade[ j ] > grade[ j+1 ] )
{
tmp = grade[j+1];
grade[j+1] = grade[j];
grade[j] = tmp;
}
}
}
printf( "after sort : ");
for(i=0;i<8;i++)
{
printf("%.1f ",grade[i]);
}
printf("\n");
system( "pause" );
return 0;
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言