嘿,我不明白爲什麼我的兩個輸入同時採取元素作爲輸入。我在TurboC編譯器GCC上試過這個代碼,但得到了同樣的錯誤。錯誤當輸入
#include <stdio.h>
int menu();
void bubble_short();
void selection_short();
int main()
{
int ch,j,n,a[100];
ch=menu();
switch (ch)
{
case 1:
{
bubble_short();
break;
}
case 2:
{
selection_short();
}
default :
break;
}
}
void bubble_short()
{
int i,j,n,a[100];
printf("Elements");
scanf("%d",&n);
for (j=0; j<n;j++)
{
scanf("%d",&a[j]);
}
for (i=0;i<n;i++)
{
for (j=0;j<n-1-i;j++)
{
if (a[j]>a[j+1])
{
a[j]=a[j]+a[j+1];
a[j+1]=a[j]-a[j+1];
a[j]=a[j]-a[j+1];
}
}
}
printf("the sorted elements are :\n");
for (i = 0; i < n; i++)
{
printf("%d\n",a[i]);
}
}
void selection_short()
{
int i,j,n,a[100],min;
printf("Elements");
scanf("%d",&n);
for (i = 0; i <n-1; ++i)
{
min=i;
for (j = 1+i; i < n; ++i)
{
if(a[min]>a[j])
min=j;
}
if(i!=min)
{
a[i]=a[i]+a[min];
a[min]=a[i]-a[min];;
a[i]=a[i]-a[min];;
}
}
printf("the shorted elements are :\n");
for (i = 0; i < n; ++i)
{
printf("%d\n",a[i]);
}
}
int menu()
{
int k;
printf("Enter the choice \n 1. bubble short \n 2. selectionshort");
scanf("\n %d ",&k);
return k;
}
嘿,我不明白爲什麼我這是採取兩個輸入,而以元素作爲輸入。我在TurboC編譯器GCC上試過這個代碼,但得到了同樣的錯誤。
輸出
'void bubble_short(int n)' - >'void bubble_short(void)' – BLUEPIXY
這是什麼錯誤?據你解釋,你得到兩次相同的錯誤。你想讓我們去你的地方看看嗎?把它放在這裏並且讓我們讀它會更容易嗎? –
我在這裏附上我的C文件。我不知道爲什麼scanf之前運行的比printf。我在此附上完整的代碼。執行後,它應該只需要一個輸入,它取2,最後一個是第二個scanf。 – akashmagrawal