Problem here
Solution
N增加1, 總正方形數會增加N*N
#include <iostream>
#include <memory.h>
using namespace std;
int mark[101];
int main(){
int n;
memset(mark, 0, sizeof(mark));
while(cin >> n){
if(n == 0)
break;
for(int i = 1 ; i <= n; i++)
if(mark[i] == 0)
mark[i] = mark[i-1] + (i*i);
cout << mark[n] << endl;
}
return 0;
}
No comments:
Post a Comment