Problem 6
#include <iostream> #include <cmath> using namespace std; #define NUM 100 int main(int argc, char **argv) { double sp; // 和の二乗 double ps; // 二乗数の和 // 和の二乗 sp = 0; for (int i = 1; i <= NUM; i++) { sp += i; } sp = pow(sp, 2.0); // 二乗数の和 ps = 0; for (int i = 1; i <= NUM; i++) { ps += pow((double)i, 2.0); } printf("%d\n", (int)(sp-ps)); return 0; }