星期四, 3月 25, 2010

Test for syntax highlight by programming a simple sort function program in C language

Actually, I wanted to set the syntax highlight before, but I don't know why I didn't set it until now. You can find how to set the syntax highlight from here.
##CONTINUE##

#include 

int main()
{
 int num[5];
 int i,j,temp;
 printf("請輸入五個整數:\n");

 for (i=0;i<5;i++)
 {
  printf("第%d個數字:",i+1);
  scanf("%d", &num[i]);
 }
 printf("您所輸入的數字為:\n");

 for (i=0;i<5;i++)
 {
  printf("%d ",num[i]);
 }

 // begin to sort data
 for (i=0;i<5;i++)
 {
  for (j=0;j<4;j++)
  {
   if (num[j] > num[j+1])
   {
    temp=num[j];
    num[j]=num[j+1];
    num[j+1]=temp;
   }
  }
 }
 
 printf("\n由大到小排序為:\n");
 for (i=0;i<5;i++)
 {
  printf("%d ",num[i]);
 }
 printf("\n");

 return 0;
}