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

刚刚学了循环,1到n的求和与阶乘

时间:2016-04-16 17:04:16      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:


//求和
int a = Convert.ToInt32(Console.ReadLine());
int c = 0;
for (int b = 0; b <= a; b++)
{
c = c + b;

}
Console.Write(c);

 

//阶乘
int a = Convert.ToInt32(Console.ReadLine());
int end = 1;
for (int b=1; b<=a;b++ )
{
end = end * b;

}
Console.Write(end);

刚刚学了循环,1到n的求和与阶乘

标签:

原文地址:http://www.cnblogs.com/zzc134680/p/5398430.html

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