#include
void main()
{
int i,n,nl,sum=0;
printf("请输入n:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
nl=i;
nl*=nl;
sum+=nl;
}
printf("输出sum:\n");
printf("sum=%d",sum);
}
# include "iostream.h"
int Fun(int n){
int sum=1,i=1,SUM=0;
for(i=1;i<=n;i++){
sum*=i;
SUM+=sum;
}
return SUM;
}
void main(){
int n;
cout<<"你要计算1的阶层加到n的阶层,请输入n\nn: ";
cin>>n;
cout<<"从1!加到"<
递归实现就好了饿。
long mul(int n)
{
long sum=1;
if(n>1)
sum=sum*mul(n-1)
else
sum*=1;
return sum;
}
long mul1(int n)
{
long sum1;
for(int i=1;i<=n;i++)
sum1+=mul(i);
return sum1;
}
void main()
{
int m;
printf("input a integer:");
scanf("%d",&m);
printf("result is: %d",mul1(m));
}
long fun(int n)
{
int i,s=1;
long k=0;//用于存储加和结果
for(i=1;i<=n;i++)
{
s*=i;
k+=s;
}
return s;
}
单循环和递归实现!