HW-1 for Chen
- #include <iostream>
- using namespace std;
- int main()
- {
- int floor = 1;
- int N;
- int count = 0;
- cout << "輸入層數N:";
- cin >> N;
- for (int i = 1; i <= N; i++)
- {
- if (i == 1)
- count++;
- else
- {
- count += i + floor;
- floor += i;
- }
- }
- cout << "當蘋果堆疊" << N << "層時,金字塔總共放了" << count << "個蘋果" << endl;
- system("pause");
- return 0;
- }
留言
張貼留言