the sum

program that will accept a number n and display the sum of all even numbers and the sum of all odd numbers from 1 to n
what have you got so far?
nothing i don't even know on how to start it
Go through all the material that your course has had so far.
Then read http://www.cplusplus.com/doc/tutorial/
tn. I've done with that already and we are now in iterative statements

sorry for my first statement,, i'am just trying to get some help regarding with that question. hope you can help me through
An odd number divided by 2 always produces a remainder equal to 1.
An even number divided by 2 always produces a remainder equal to 0.

To get the remainder of a number we will use the modulo operator %

So I will write a function that will retrun the sum of even numbers.

1
2
3
4
5
6
7
8
9
10
11
int EvenSum(int n)
{
	int EvenSum=0;  // initializing the sum with 0
	for(int i=0; i<=n; i++)
		if (i%2==0)     // if i is even
		{
			EvenSum+=i;   //every time i is even we add i to the sum
		}
		return EvenSum;
}


In main we will call the function

1
2
3
4
5
6
7
8
9
10
int main()
{
	int n;
	cout<<"n="; 
        cin>>n;   
	cout<<EvenSum(n);  // calling the function

	_getch();
}


Using the same idea you can do a function for Odd Numbers.
If you have any questions feel free to answer.
tnx. it really helps me a lot..

i still have a question

.. A program that will compute for n! ( n factorial) which is the product of all numbers from 1 to n.

hope you can still help me with this
its similar to the previous problems

int factorial =1;

for(int i=1; i<=N; i++)
{
factorial = factorial*i;
}
I got a bet confuse about the program,, imean how should i write it in
turbo c ?
yes turbo c++,
This is a simple factorial program. It doesn't matter what compiler or IDE you're using. bubba89 already gave you the answer. Have you even tried to compile it or are you just waiting for someone to do ALL the work for you?
Topic archived. No new replies allowed.