Category:第七届蓝桥杯C语言B组(省赛)
Article From:https://www.cnblogs.com/chiweiming/p/9124156.html

Original


Number of coal balls

There is a pile of coal balls in the shape of a triangular pyramid. Specific:
1, on the first floor.
Second layers of 3 (arranged in triangles),
Third layers of 6 (arranged in triangles),
Fourth layers of 10 (arranged in triangles),
….
If there are 100 layers in all, how many coal balls are there in all?

Please fill in the number of the total number of coal balls.
Note: you should submit an integer, do not fill in any redundant content or explanatory text.

 

Layer number 123456…

The number of briquettes is 136, 1015, 21…

        +2    +3     +4     +5    +6

public class The number of coal balls {public static void main(String args[]) {
        int total=1;
        int cent=1;
        int i=0;
        for(i=2;i<=100;i++) {
            cent+=i;
            total+=cent;
        }
        System.out.println(total);
    }
}

23:59:24

2018-06-01

Leave a Reply

Your email address will not be published. Required fields are marked *