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; }
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; }
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.
Thanks all of you.
Finished.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"