Problem Statement
Explanation: How many squares a (4x4) square holds? the answer is-
which is also equivalent to
Solution:
#include<stdio.h>
int main()
{
int n,x;
while(scanf("%d",&n)&&n!=0)
{
x=(n*(n+1)*((2*n)+1))/6;
printf("%d\n",x);
}
return 0;
}
Explanation: How many squares a (4x4) square holds? the answer is-
16 (1x1) squares + 4 (2x2) squares, 9 (3x3) squares, 1 (4x4) squaresMeaning, the answer is n²+ (n-1)²+(n-2)²+.......+1²
which is also equivalent to
Solution:
#include<stdio.h>
int main()
{
int n,x;
while(scanf("%d",&n)&&n!=0)
{
x=(n*(n+1)*((2*n)+1))/6;
printf("%d\n",x);
}
return 0;
}
Comments
Post a Comment