C++經典編程題目(十)計算方塊個數

 10. 如圖1所示,編寫程序計算               ┎┰┰┰┰┰┰┰┰┰┒
 大大小小正方形共有多少?當最小          ┠╂╂╂╂╂╂╂╂╂┨
 正方行邊長爲1時,它們的總面積          ┠╂╂╂╂╂╂╂╂╂┨
 共爲多少?                                              ┠╂╂╂╂╂╂╂╂╂┨
                                                                 ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┠╂╂╂╂╂╂╂╂╂┨
                                                                ┖┸┸┸┸┸┸┸┸┸┚

#include "stdio.h"
#include <iostream>
using namespace std;

#define N  10

void main()
{
	int a[10];
	int count = 0;
	int numOfSquare = 0;
	int area = 0;

	for (int i = 0; i < N; i++)
	{
		a[i] = (N - i)*(N - i); 
		numOfSquare += a[i];
		area += a[i] * (i + 1) * (i + 1);
	}

	printf("count = %d, total area = %d\n", numOfSquare, area);
	system("pause"); 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章