whats wrong with this code?
when i enter 10 as N.... it displays 81
when i enter 6 as N... its displays 25
can someone please edit or explain?
thanks!
Code:
#include <stdio.h>
void display(int n);
int main(void)
{
int n;
clrscr();
printf("\nThis program computes and displays\n");
printf("the sum of the first N perfect squares.");
printf("\n\nEnter the value of N:\t");
scanf("%d", &n);
display(n);
getche();
return 0;
}
void display(int n)
{
int i;
int j;
int sum = 0;
for(i = 0, j = 0; i < ( n - 1 ); i++, j++);
{
printf("%d +", ( j * j ));
sum = sum + (j * j);
}
printf("\n\n%d", sum);
}