ช่วยเรื่องเขียน Straight Insertion ภาษาซี หน่อยคับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

Booooooooo
PHP Newbie
PHP Newbie
โพสต์: 1
ลงทะเบียนเมื่อ: 14/02/2011 12:56 pm

ช่วยเรื่องเขียน Straight Insertion ภาษาซี หน่อยคับ

โพสต์ที่ยังไม่ได้อ่าน โดย Booooooooo »

ผมทำได้แค่นี้อ่าคับ
ส่วนของการแสดงผลยังไม่ถูก คือมันต้องแสดง รอบแรก สองตัว สามตัว สี่ตัว ตามลำดับอ่าคับ
ช่วยด้วยนะคับ ผมงมมาหลายคืนแล้ว :?

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int main()
{
int choice;
int num[]={},a,amount,tmp, i, j;

do{
system("cls");
printf("\tStraight Insertion\n\n");
printf("1.Run Program\n");
printf("0.Exit\n");
printf("\n\nEnter choice : ");
scanf("%d",&choice);

switch(choice){
case 1:
{

system("cls");
printf("Enter Amount Number in List < Min number is 10 > : ");
scanf("%d",&amount);

if(amount >=10)
{
for(a=0;a<amount;a++)
{

printf("Enter number [%d]: ",a+1);
scanf("%d",&num[a]);
}

for(i = 1 ; i < amount ; i++)
{

for(j = i ; j > 0 ; j--)
{

if(num[j] < num[j-1])
{
tmp = num[j];
num[j] = num[j-1];
num[j-1] = tmp;
}else
{
break;
}
}

printf("\nSort [%d] : ",i);

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




printf("\n");
}

}
else
{
system("cls");
printf("Amount >= 10\n");
}
break;
}
case 0:
{

break;
}
default :
{
printf("Please select choice\n");
}
}
system("pause");
}while(choice != 0);

system("cls");
printf("End program\n");
system("pause");
return 0;
}
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 93