跪求C程题的答案,急用,谢了!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:25:12
2. 编写函数double fun(double m,int n),计算并返回如下n+1项数据的乘积:

第2项 第3项 第4项 第n+1项
m与n值由实参传递。例:m=2,n=5时,z=3.140331
#include<math.h>
double fun(double m,int n)
{
}
void main()
{double x,z;int y;
scanf("%lf%d",&x,&y);
z=fun(x,y);
printf("the result=%lf\n",z);
}
3. 编写函数int fun(int m),计算并返回满足表达式:1+(1+2)+(1+2+3)+(1+2+3+4)+……+(1+2+3+……+n)<=m最大的n。例如,当m=10000时,程序输出:n=38。
int fun(int m)
{
}
void main()
{int x;
scanf("%d",&x);
printf("n=%d\n",fun(x));
}
4. 编写函数void fun(int *x,int n),它的功能是:求出数组x中的最小数和次最小数,并把最小数和a[0]中的数对调、次最小数和a[1]中的数对调,其余的数保持不变。如程序运行时若输入:2 4 6 11 3 9 7 0 5 8,则输出:0 2 6 11 3 9 7 4 5 8。
#define N 10
void fun(int *x,int n)
{
}
main()
{int a[N],i;
for(i=0;i<N;i++)
scanf("%d",a+i);
fun(a,N);
for(i=0;i<N;i++)

第一个不知在说什么....
第三个复制一下数组,再把副本排序一下就OK啦
第二个:
int fun2(int n)
{
int t;
if(0==n)
return 0;
t=n*(n+1)/2;
return t;
}
int fun(int m)
{
int t=0, i;
if(0==m)
return 0;
for(i=1;;i++)
{

t+=fun2(i);
if(t>m)
{

break;
}
}
return i-1;
}

你是用的调用函数对吧!等过几天我发给你