Hi..
i did this program but it gave me wrong in this step:sum=sum+pow(i&2);
So What is the mistake?
Thanks all!
#include <iostream>
#include <cmath>
using namespace std;
int main()
{ int m;
int num;
int sum=0;
cout<<"Enter a postive integer";
cin>>m;
for (int i=1;i<=num;i++)
sum=sum+pow(i&2);
cout<<"the sum of the first"<<num<<"squares is"<<sum<<endl;
cin>>m;
return 0;
}
The pow function takes two parameters. You appear to be trying to hand it i&2 which is the inti bitwise ANDed with the number 2. I suspect you don't know what that means, so it's likely you didn't intend that at all.
Try this instead: sum=sum+pow(i,2);
If you're trying to output the first num squares, shouldn't cin>>m;
be cin>>num;?