i tried to create a program that would get the sum of the squares but i couldn't get the right output. Could u help me debug? and tell which part of my codes where wrong.PLEASE!
:S

#include<iostream.h>
#include<conio.h>
#include<math.h>
int x,num;
int f(int);
main ()
{

clrscr();
    cout<<"Enter a number: ";
    cin>>num;
    cout<<f(num);
getch ();
return 0;
}
int f(int s)
{
for(x=1;x<=s;x++)
{
int ans2;
 int y;
int ans[10];
ans[y]=pow(x,2);
ans2=ans[y]+ans[y];
cout<<ans2;
y++;
}
return 0;
}

move lines 20, 21 and 22 up between lines 17 and 18 (outside the loop)

commented: Shortest working answer of the week :) +36

thanks for the help.
i really appreciate the effort,
but i still couldn't get the right output.

I finally got the correct codes.:icon_cheesygrin:
thanks for those who helped....:)

i tried to create a program that would get the sum of the squares but i couldn't get the right output. Could u help me debug? and tell which part of my codes where wrong.PLEASE!


firend
hi...
your program is totally correct
but u r not getting ur output properly
so put

cout<<" "<<ans2;
instead of cout<<ans2;

okay...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.