Write a program that inputs a positive number.It then display the sum of all odd numbers and then sum of all even numbers from 1 to the number entered by the user.

Write  a program that inputs a positive number.It then display the sum of all odd numbers and then sum of all even numbers from 1 to the number entered by the user.



#include<iostream>
using namespace std;
int main ()
{
int n,i,e,o;
e=0;
o=0;
cout<<"\t * Sum of Even and Off Numbers * "<<endl;
cout<<"\n";
cout<<"Enter the number"<<endl;
cin>>n;
for (i=1; i<=n; i++)
{
if (i%2==0)
{
e=e+i;
}
else
{
o=o+i;
}
}
cout<<"\n";
cout<<"The Sum of all even numbers = "<<e<<endl;
cout<<"The Sum of all odd numbers = "<<o<<endl;
}

Write  a program that inputs a positive number.It then display the sum of all odd numbers and then sum of all even numbers from 1 to the number entered by the user.