急急啊!! 帮我写C程序 是数组那章的 涕泪感激

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:24:19
1、在一个5个元素的升序排列的数组中,任意输入一个数插入其中,要求保持原来的排列顺序。输出结果。
2、写一程序,要求将字符串a的第n个字符之后的内容由字符串b替代,a,b,n由运行时输入。

第1题:
#include <stdio.h>

#define MAX_SIZE 6 /* 数组的最大容量 */
#define SIZE 5 /* 当前数组种的元素个数 */

int main()
{
int i = 0;
int temp; /* 交换值时用来作临时存储 */
double num[MAX_SIZE] = {1, 3, 5, 7, 9};

printf("Please input a number : ");
scanf("%f", num + SIZE); /* 将新数保存到数组
最后一个位置 */
for (i = SIZE; i > 0; i--)
{
/* 如果当前数字比它前面的小,则交换二者 */
if (num[i] < num[i - 1])
{
temp = num[i];
num[i] = num[i - 1];
num[i - 1] = temp;
}
else /* 如果当前字符比之前的大,则
它已经处于正确的位置 */
{
break;
}
}
return 0;
}

第2题:

#include <stdio.h>
#include <string.h>

#define SIZE 1000

int main()
{