helppppp

i need to print the first N triangular and square numbers (both of them) so if i type 3 it should give me 1 36 1225. these are the first three numbers which are both triangular and square. i only managed to print both numbers until a given number. lets say l=8. it will print only 1 and 36 and its wrong it should print 8 numbers. i think this has to do with recursive function but i cannot find a formula for this

void display_tring_sq (double l) // a function being defined
{
int i = 1;
while(i <= l)
{ int a=i*(i+1)/2;
int j = 1; // Resets for each iteration of the first loop
while(j <= l)
{ int b=j*j;
if (a==b)
cout <<a<<endl;
j++;
} // End of the nested loop
i++; // Increment the first loop counter
} // The end of the first loop
}
aubg ?
Topic archived. No new replies allowed.