#include <stdio.h>
#include <conio.h>
int main()
{
int array[100], num1, c, n, num2;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
printf("Enter the number to swap\n");
scanf("%d", &num1);
printf("Enter the number to swap with\n");
scanf("%d", &num2);
printf("%d is swap place with %d.\n", num1, num2);
for (c = 0; c < n; c++)
{
if (array[c] == num1)
{
array[c] = num2;
}
else if (array[c] == num2)
{
array[c] = num1;
}
}
printf("The new output will be\n");
getch();
return 0;
}
こんにちは、コードの途中までやっていますが、続行する方法がわかりません。リスト内のスワップ番号をコーディングしています。誰かが私を助けることができますか?
配列内の要素の数を入力してください: 5 5 つの要素を入力してください 2 4 6 8 0 入れ替える最初の数字を入力してください: 8 入れ替える 2 番目の数字を入力してください: 2 8 は 2 と場所を入れ替えます。出力は次のようになります: 8 4 6 2 0
-1 を入力してプログラムを終了するにはどうすればよいですか? 例: 配列の要素数を入力: -1 出力: プログラムを終了します。