-2
Cで配列を使用せずに、キーボードから入力された整数を昇順でソートして出力することです。入力の終わりには「-1」と記されていますが、これは入力とはみなされません。 私はこれを解決しようとしましたが、成功できませんでした。Cで配列を使用せずにキーボードから昇順にソートしてプリントする
はここで、我々は最終的に、我々は数字のソートセットを取得し、ECHのステップに挿入ソートを行うキーボードから1ずつ番号1を入力することができ、私の試みこれで
#include<stdio.h>
void smaller(int first,int second)
{
int temp=0;
if(second<first) {
temp=first;
first=second;
second=temp;
printf("%d %d",first,second);
}
}
int main()
{
int first=0,second=0;
printf("Kindly enter numbers to be arranged in ascending order followed by a -1\n\n");
scanf("%d",&first);
while(second != -1) {
scanf("%d",&second);
smaller(first, second);
}
return 0;
}
入力が必要な順番で行われていない限り、再帰が必要であると思われたり、データをファイルに保存したりします。 – chux
リンクリストはどうですか? –
@ JerryJeremiahこれは、https://codegolf.stackexchange.com/で非常に歓迎されるアプローチです:) – klutt