Answered # operator confusion

siddhant3s 1,429 Clockowl 56 siddhant3s 1,429 Discussion Starter jam7cacci Discussion Starter jam7cacci Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

I'm trying to add all the square root answer but why am i getting this output: -858993430

```
#include <iostream.h>
void main()
{
int input;
int sqrt;
int i, sum, add;
cout << "Please enter your desire number: ";
cin >> input;
for (i=1; i <= input; i++)
{
sqrt = i * i;
add = sqrt;
cout << i << "^2 = " << sqrt<< "\n";
sum += add;
}
cout << "the sum is: " << sum;
}
```

what could be wrong? hope you could help me with this. thanks!

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting

0

Please. Please

Don't use void main. http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

And yes, you are adding the squares of the integer rather than the square root.

To find the square root, you need to #include <cmath> and use the pow() function.http://www.cppreference.com/wiki/c/math/pow

0

To find the square root, you need to #include <cmath> and use the pow() function.http://www.cppreference.com/wiki/c/math/pow

He means the sqrt() function.

0

No, I really meant pow() function.

It is more versatile than sqrt().

You can use pow(N,0.5) rather than sqtr(N)

0

Please. Please

Don't use void main. http://cppdb.blogspot.com/2009/02/sh...t-main-or.html

And yes, you are adding the squares of the integer rather than the square root.

To find the square root, you need to #include <cmath> and use the pow() function. http://www.cppreference.com/wiki/c/math/pow

thanks!

i got it! hmmm.... i cant use other than void... i'm not a pro yet and i must stick with the way my prof has taught us. though yah it would be nice to experiment from time to time but as now i have to stick with it :(. new ways are hard for me to understand especially when you have tones of assignments regarding it! hahaha!

but anyway, i appreciate it! thank a lot everybody!

so here's my code and glad to have it work... after how many paper scratches for computation.. :(

```
#include <iostream.h>
void main()
{
int input;
int sqrt;
int i, sum, add;
cout << "Please enter your desire number: ";
cin >> input;
cout << "\n" ;
for (i=1; i <= input; i++)
{
sqrt = i * i;
cout << "\n" << i << "^2 = " << sqrt<< "\n";
sum = sum + sqrt;
}
add = 0;
for (i=0; i <=input; i++)
{
sum = i * i;
add = add + sum;
}
cout << "\nThe sum is: " << add << "\n\n";
}
```

now my next problem is how to do the sum of powers from 1 to n :(

when the user inputted 4

it should be

```
1^1 = 1
2^2 = 4
3^3 = 27
4^4 = 256
```

whew... :(

now it's getting more confusing....

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting

0

It is more versatile than sqrt().

You can use pow(N,0.5) rather than sqtr(N)

hahaha!

i tried the pow! ya you're right it was much easier to use...

thanks again!

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...