码迷,mamicode.com
首页 > 其他好文 > 详细

输入n,计算并输出n1+n2+n3+……+n10

时间:2014-07-27 10:19:12      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

// 方法1:双重循环

#include <stdio.h>

void main()

int i,j,n,s,t;   

scanf("%d",&n);   

s=0;    

for (i=1; i<=10; i++)   

t=1;  

for (j=1; j<=i; j++)  

 t=t*n;  

s=s+t;  

  }   

printf("%d\n",s);

}

 

 

 

// 方法2:单循环

#include <stdio.h>

void main()

{

   int i,n,s,t;   

  scanf("%d",&n);   

  s=0;

t=1;     

 

for (i=1; i<=10; i++)  

   { t=t*n;  

s=s+t;     }   

 

  printf("%d\n",s);

}

 

 

// 方法3: //多项式的计算方法

#include <stdio.h>

void main()

  int i,n,s;   

  scanf("%d",&n);  

   s=0;     

  for (i=1; i<=10; i++)  

s=(1+s)*n;    

printf("%d\n",s); }

 

 

// 方法4:利用数学公式

#include <stdio.h>

 

#include <math.h>

 

void main()

{  

int i,n,s;

     scanf("%d",&n);    

  s=n*(1-pow(n,10))/(1-n);      // ??????????????????????????????/

 

printf("%d\n",s); }

 

输入n,计算并输出n1+n2+n3+……+n10

标签:

原文地址:http://www.cnblogs.com/wc1903036673/p/3870569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!