#include
double f(int n)
{
double a[10000], b;
a[1]=n;
for(int i=1;i
a[i+1]=a[i]+n+i;
b=a[i+1];
}
return b;
}
void main()
{
int n;
double k;
cout<<"请输入整数n:";
cin>>n;
k=f(n);
cout<<"函数的值为:"<
已经验证过过了,a[10000]表示当中可以存放的数据个数,可以改动。不过,必须小于n,不能等于
#include "stdio.h"
double f(int n)
{
int i;
double sum=0;
for(i=1;i<=n;i++)
sum=sum+n;
n++;
return sum;
}
main()
{
int i,n;
scanf("%d",&n);
printf("%lf",f(n));
}
虽然有点晚吧
double f(int n)
{
double sum=0;
int i;
for(i=n;i<=2*n-1;i++)
sum=sum+i;
return sum;
}
public class Test {
public static void main(String[] args) {
double n=10;
double result=fmethod(n);
System.out.println(result);
}
public static double fmethod(double n) {
double r=0;
for (double i = n; i < =(2*n+1); i++) {
r+=i;
}
return r;
}
}
int main(n)
{
x=n+(n+1)+...(2n+1);
return x;
}