[LOOPS only] can i ask what is wrong with this code?

Huskar

New member
Joined
Mar 18, 2009
Messages
1
Reaction score
0
Points
1
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!



#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);
}
 
Back
Top