题解 | #有序序列插入一个整数#
有序序列插入一个整数
https://www.nowcoder.com/practice/444e87f938464906a1649cff236b102b
#include<stdio.h> int main() { int n = 0, x = 0; scanf("%d ", &n); int arr[50] = {0}; for (int i = 1; i <= n; i++) { scanf("%d ", &arr[i]); } scanf("%d ", &x); int j; for (j = n; j > 0; j--) { if (x > arr[j]) { arr[j + 1] = x; break; } arr[j + 1] = arr[j]; arr[j] = x; } for (int i = 1; i <= n + 1; ++i) printf("%d ", arr[i]); return 0; }
c语言刷题 文章被收录于专栏
c语言刷题题目