夕阳玻璃 发表于 2006-2-28 10:43

〖求助〗哪位高手帮我看看我这个程序错在哪啊?

一维数组的比较法排序

#include<stdio.h>
main()
{
int k,i,j,t,a;
printf("put in data\n");
for(i=0;;i++)
{
   scanf("%d",&a);
   if(a<0)break;
   }
   for(j=0;j<i-1;j++)
   {
      for(k=j;k<i-1;k++)
       {if(a<a)
      {
         t=a;
         a=a;
         a=t;
         }
       a=a;
       }
      }
for(j=0;j<i;j++)
printf("%4d",a);
getch();
}

夕阳玻璃 发表于 2006-2-28 14:02

谁帮帮我啊?

feelingai 发表于 2006-2-28 14:52

貌似LZ是用冒泡法...

把小的数放前...

feelingai 发表于 2006-2-28 14:52

#include<stdio.h>
main()
{
int k,i,j,t,a;
printf("put in data\n");
for(i=0; ;i++)
{
scanf("%d",&a);
if(a<0)break;
}
for(j=0;j<i-1;j++)
   {
   for(k=j;k<i-1;k++)
    {if(a<a)
      {
      t=a;
      a=a;
      a=t;
      }
    a=a;
    }
   }
for(j=0;j<i;j++)
printf("%4d",a);
getch();
}

看不懂这句是什么意思...

feelingai 发表于 2006-2-28 14:56

建议LZ写程序多用注释...

虽然很短....

墙角野猫 发表于 2006-2-28 17:13

<P>#include<stdio.h><BR>main()<BR>{<BR>int k,i,j,t,a;<BR>printf("put in data\n");<BR>for(i=0; ;i++)<BR>{<BR>scanf("%d",<FONT color=#ff0000>&a</FONT>);<BR>if(<FONT color=#ff0000>a</FONT><0)break; /*a是数组名,是指针*/<BR>}<BR>for(j=0;j<i-1;j++)<BR> {<BR> for(k=j;k<i-1;k++)<BR> {if(a<a)<BR> {<BR> t=a;<BR> a=a;<BR> a=t;<BR> }<BR><FONT color=#ff0000>/* a=a; */</FONT><BR> }<BR> }<BR>for(j=0;j<i;j++)<BR>printf("%4d",a);<BR>getch();<BR>}<BR></P>

墙角野猫 发表于 2006-2-28 17:36

还是有问题!

墙角野猫 发表于 2006-2-28 17:44

#include<stdio.h><BR>main()<BR>{<BR>int k,i,j,t,a;<BR>printf("put in data\n");<BR>for(i=0; ;i++)<BR>{<BR>scanf("%d",<FONT color=#ff0000>&a</FONT>);<BR>if(<FONT color=#ff0000>a</FONT><0)break; <FONT color=#ff0000>/*a是数组名,是指针*/</FONT><BR>}<BR>for(j=0;j<i-1;j++)<BR> {<BR> for(k=<FONT color=#ff0000>0</FONT>;k<i-1-j;k++)<FONT color=#ff0000>/*第二次循环从0开始,不是从j开始,j是变量会变化*/</FONT><BR> {if(a<a)<BR> {<BR> t=a;<BR> a=a;<BR> a=t;<BR> }<BR><FONT color=#ff0000>/* a=a; */</FONT><BR> }<BR> }<BR>for(j=0;j<i;j++)<BR>printf("%4d",a);<BR>getch();<BR>}<BR>

色恩 发表于 2006-2-28 17:46

明显是乱码…

墙角野猫 发表于 2006-2-28 17:52

没大问题了,WIN-TC编译通过,
put in data
5(Enter)
3(Enter)
6(Enter)
8(Enter)
4(Enter)
9(Enter)
-1(Enter)
986543
页: [1] 2
查看完整版本: 〖求助〗哪位高手帮我看看我这个程序错在哪啊?