请问一下这个问题。

「已注销」 2017-11-10 12:32:20
1.自定义函数double polyfunc(double dArray[], int item, double x),实现一个求由数组dArray表示的多项式的值的函数,其中item为多项式的项数,并在主程序中测试该函数。

数组是才学的,不是很会用,而且还要用函数编,无从下手啊。。很难过,希望能受教学习一番

2.输出n个整数,将这n个数的前m<n/2个数和后m个数交换(数据块交换),要求m从键盘输入。
例如,设有20个数为
23 19 88 71 23 55 32 18 9 2 22 72 66 55 80 33 17 0 102 7
如果m=5,则结果为
33 17 0 102 7 55 32 18 9 2 22 72 66 55 80 23 19 88 71 23 
交换过程由函数实现,函数原型 void BlockExchange(int nArray [], int n, int m); 或void BlockExchange(int * pArray, int n, int m); 在主程序输入数据并调用该函数实现交换,然后在主程序中输出。

这个问题我做了一部分发现也做得不对了,要求是数据块交换,我这样好像只能相邻的比大小交换,所以还请指点一下

#include <stdio.h>
void sort(int nArray[], int n)
{
int i,temp;
for(i=0;i<=8;i++)
{
if(nArray[i]<nArray[i+1])
{
temp=nArray[i+1];
nArray[i+1]=nArray[i];
nArray[i]=temp;
}
}
return void sort();
}
int main()
{
int nArray[];

}
...全文
369 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2017-11-10
  • 打赏
  • 举报
回复
#include<stdio.h>

static void print(const int *arr, int size);
void block_exchange(int *arr, int n, int m);

int main()
{
    int num_list[20], n, m;
    int i;

    while (scanf("%d", &n) == 1 && (n < 10 || n > 20))
        ;

    printf("n = %d\n", n);
    i = 0;
    while (i < n)
        scanf("%d", &num_list[i++]);
    printf("i = %d\n", i);

    printf("Num list: \n");
    print(num_list, n);
    printf("Please input a number:");
    scanf("%d", &m);
    block_exchange(num_list, n, m);
    print(num_list, n);

    return 0;
}

void block_exchange(int *arr, int n, int m)
{
    if (m >= n / 2)
        return;
    int *pend, *pstart, *pdst;

    pstart = arr;
    pend = arr + m;
    pdst = arr + n - m;
    while (pstart < pend) {
        int tmp = *pstart;
        *pstart = *pdst;
        *pdst = tmp;
        pstart++;
        pdst++;
    }
}

static void print(const int *arr, int size)
{
    int i;

    for (i = 0; i < size; i++)
        printf("%d  ", arr[i]);
    putchar(10);
}

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧