C语言:大佬,下面图片上的题目咋写?
代码文本:
#include "stdio.h"
#define N 10
int main(int argc,char *argv[]){
int a[N+1],i,j,k;
printf("Please enter %d integer(s) from small to large...\n",N);
for(i=0;i<N;i++){//输入数据并输出
if(scanf("%d",a+i)!=1 || (i && a[i]<a[i-1])){
printf("Error! Please enter an integer is greater than %d...\n",a[i-1]);
i--;
}
printf("%d ",a[i]);
}
putchar('\n');
printf("Please enter an integer to be inserted...\n");
scanf("%d",&k);//输入要插入的数据
for(i=N-1;i>=0;i--){
if(a[i]<=k)//看看插在哪里合适
break;
a[i+1]=a[i];
}
a[i+1]=k;//插在合适的地方
for(i=0;i<=N;printf("%d ",a[i++]));//输出插入后的数组
putchar('\n');
for(i=N,j=0;j<i;j++,i--)//逆序数组
k=a[i],a[i]=a[j],a[j]=k;
for(i=0;i<=N;printf("%d ",a[i++]));//输出逆序后的
putchar('\n');
return 0;
}