- #include <stdio.h>
- #include <conio.h>
- void main()
- {
- int n = 3;
- int S;
- S = (n * (n + 1) * (2 * n + 1)) / 6;
- printf("Tong la: %i", S);
- getch();
- }
Chạy thủ công: từ 8 đến 9
S = (n * (n + 1) * (2 * n + 1)) / 6
= (3 * (3 + 1) *(2 * 3 +1)) / 6
= 14
In ra S = 14
