gpt4 book ai didi

c - 编写时给出错误答案但复制时给出正确答案的程序

转载 作者:太空宇宙 更新时间:2023-11-04 05:10:51 25 4
gpt4 key购买 nike

<分区>

我在做选择排序。我编写的程序生成了错误的结果,但是当我从站点复制它时。除了从网站上复制的代码有更多的空格外,代码完全相同。我提供了这两个代码。请帮忙我写的代码:

#include<stdio.h>
main()
{
int position, array[100], n, c, d, swap;
printf ("Enter the number of elements:\n");
scanf ("%d", &n);
printf ("Enter the %d integer\n",n);
for (c=0 ; c < n ; c++)
scanf ("%d", &array[c]);
for (c = 0 ; c < (n-1); c++)
{
position=c;
for (d = c+1; d < n; d++)
{
if (array[position] > array[d]);
position = d;
}
if (position !=c);
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
printf ("Sorted list in the ascending order:\n");
for (c=0 ; c < n ; c++)
printf ("%d\n", array[c]);
getch();
}

网站给出的代码

#include<stdio.h>

main()
{
int array[100], n, c, d, position, swap;

printf("Enter number of elements\n");
scanf("%d", &n);

printf("Enter %d integers\n", n);

for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);

for ( c = 0 ; c < ( n - 1 ) ; c++ )
{
position = c;

for ( d = c + 1 ; d < n ; d++ )
{
if ( array[position] > array[d] )
position = d;
}
if ( position != c )
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}

printf("Sorted list in ascending order:\n");

for ( c = 0 ; c < n ; c++ )
printf("%d\n", array[c]);

getch();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com