| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
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[];
 
 -         
 
 - }
 
  复制代码 
 本帖最后由 BngThea 于 2017-11-10 13:31 编辑 
你应该先说说你的思路,做一个纯伸手党的话进步就太慢了 
我给个两个问题的简单程序:
 - #include <stdio.h>
 
 - #include <stdlib.h>
 
  
- double polyfunc(double*, int, double);
 
  
- double polyfunc(double dArray[], int item,double x)
 
 - {
 
 -         double result = 0, temp;
 
 -         int i, j;
 
 -         for (i = 0; i < item; i++)
 
 -         {
 
 -                 temp = 1;
 
 -                 for (j = 0; j <= i; j++)
 
 -                 {
 
 -                         temp *= x;
 
 -                 }
 
 -                 result += dArray[i] * temp;
 
 -         }
 
 -         return result;
 
 - }
 
 - int main(void)
 
 - {
 
 -         double factors[3] = {1.2, 2.1, 3};
 
 -         double x = 2.5;
 
 -         double y = polyfunc(factors, 3, x);
 
 -         printf("%lf", y);
 
 -         system("pause");
 
 -         return 0;
 
 - }
 
  复制代码 
- #include <stdio.h>
 
 - #include <stdlib.h>
 
  
- void BlockExchange(int nArray [], int n, int m); 
 
  
- void BlockExchange(int nArray [], int n, int m)
 
 - {
 
 -         int temp, i, j;
 
 -         for (i = 0; i < m; i++)
 
 -         {
 
 -                 j = n - m + i;
 
 -                 temp = nArray[i];
 
 -                 nArray[i] = nArray[j];
 
 -                 nArray[j] = temp;
 
 -         }
 
 - }
 
  
- int main(void)
 
 - {
 
 -         int arr[] = {23,19,88,71,23,55,32,18,9,2,22,72,66,55,80,33,17,0,102,7};
 
 -         int len = sizeof(arr)/sizeof(int);
 
 -         int m, i;
 
 -         printf("请输入一个小于%d的正整数:", len/2);
 
 -         scanf("%d", &m);
 
 -         BlockExchange(arr, len, m);
 
 -         for (i = 0; i < len; i++)
 
 -         {
 
 -                 printf("%d ",arr[i]);
 
 -         }
 
 -         system("pause");
 
 -         return 0;
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |