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

数数小木块

时间:2014-11-02 18:07:46      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   for   sp   strong   

数数小木块

描述

在墙角堆放着一堆完全相同的正方体小木块,如下图所示:

bubuko.com,布布扣

 

 因为木块堆得实在是太有规律了,你只要知道它的层数就可以计算所有木块的数量了。

现在请你写个程序 给你任一堆木块的层数,求出这堆木块的数量.

 
输入
第一行是一个整数N(N<=10)表示测试数据的组数) 接下来的n行 每行只有一个整数 ,表示这堆小木块的层数,
输出
对应每个输入的层数有一个输出,表示这堆小木块的总数量,每个输出占一行
样例输入
2
1
5
样例输出
1
35

 
#include <iostream>
#include <string>
using namespace std;

int main()
{
int n,m;
int b;

cin>>n;
while(n--){
    cin>>m;
    b = 0;
    for(int i=m;i>=1;i--)
        for(int j=1;j<=i;j++)
            b +=j;
    cout<<b <<endl;

}


return 0;
}        

 

数数小木块

标签:style   blog   http   io   color   os   for   sp   strong   

原文地址:http://www.cnblogs.com/imwtr/p/4069549.html

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