# Need some answers to these super short problems

Printable View

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 01-12-2010
C_Sparky
Quote:

Originally Posted by Sebastiani
Just FYI, gratuitous space != obfuscation. ;)

Yeah I just wanted to quickly make something confusing looking so that's what I got :)
• 01-12-2010
dnilra
Quote:

Originally Posted by Sebastiani
Alternately, you can use Gauss's equation: ( N * ( N + 1 ) ) / 2.

Heres what I did:
Code:

```#include <iostream> //Write a program that calculates the sum N numbers. using namespace std; int main() { int N = 0; int sum = 0; cout << "Enter N...>"<< endl; cin >> N; for( int i = 1; i <= N; i = i + 1) { sum = sum + i; } cout << "The total sum of N numbers: " << sum << endl; system ("pause"); return 0; }```
• 01-12-2010
dnilra
OK take a look at this:
Write a program that calculates the sum of squares of numbers from 1 to N.

Heres what Ive done but the result (when i run) its not correct.
Code:

```#include <iostream> //Write a program that calculates the sum of squares of numbers from 1 to N. using namespace std; int main() { int N = 0; int sum = 0; cout << "Enter a number...>" << endl; cin >> N; for( int i = 1; i <= N; i = i + 1){ sum = sum*sum + i; } cout << "The total sum of of squares of numbers from 1 to N is: " << sum << endl; system ("pause"); return 0; }```
• 01-12-2010
Sebastiani
Quote:

Originally Posted by dnilra
OK take a look at this:
Write a program that calculates the sum of squares of numbers from 1 to N.

Heres what Ive done but the result (when i run) its not correct.
Code:

```#include <iostream> //Write a program that calculates the sum of squares of numbers from 1 to N. using namespace std; int main() { int N = 0; int sum = 0; cout << "Enter a number...>" << endl; cin >> N; for( int i = 1; i <= N; i = i + 1){ sum = sum*sum + i; } cout << "The total sum of of squares of numbers from 1 to N is: " << sum << endl; system ("pause"); return 0; }```

Instead of multiplying the 'sum' with itself and then adding 'i', you should be adding the product of 'i' with itself to 'sum'.

Also, for future reference, you can simply use Aryabhata's formula: ( ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ).
• 01-12-2010
dnilra
Quote:

Originally Posted by Sebastiani
Instead of multiplying the 'sum' with itself and then adding 'i', you should be adding the product of 'i' with itself to 'sum'.

Also, for future reference, you can simply use Aryabhata's formula: ( ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ).

Ok thanks I fixed that and its working :). THanks a lot.

3 to go now:
Write a program to show all the numbers that are divisible by X from 1 to n (dont have a clue)
Write a program that calculates an average of n scores entered by user (dont understand it)
Write a program to create a countdown from N to 1 and display a text as a fire (need some serious help on this)
• 01-12-2010
Sebastiani
Quote:

Originally Posted by dnilra
Ok thanks I fixed that and its working :). THanks a lot.

3 to go now:
Write a program to show all the numbers that are divisible by X from 1 to n (dont have a clue)
Write a program that calculates an average of n scores entered by user (dont understand it)
Write a program to create a countdown from N to 1 and display a text as a fire (need some serious help on this)

1) Set up a loop as you did in your previous problems. Apply the modulo operator to the increment variable. If it's zero, then X divides it evenly, so print it.
2) Read input until the user is done. Each iteration, add it to the running total, and increment a counter that keeps track of the number of entries thus far (alternately, you can prompt the user for the number of scores to be entered, beforehand, but this is a bit less flexible). After the data entry phase is complete, divide the running total by the number of entries to obtain the average.
3) Not clear on the meaning of that one.
• 01-12-2010
dnilra
Thanks all of you.

Finished.
• 01-13-2010
iMalc
Quote:

Originally Posted by dnilra
Im offering a domain in exchange for this...

Right, so you were publicly offering a bribe for others to help you break the rules?

Think again!
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12