Write a program to find the sum of even and odd numbers

//this is a program to find the sum of even and odd numbers
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
int ecount=0,ocount=0,esum=0,osum=0,i,num;

cout<<"\n\nEnter the value til, which you want to find the sum of even and odd numbers: ";
cin>>num;

for(i=1;i<=num;i++)
{
if(i%2==0)
{

esum=esum+i;
ecount++;
}
else
{
osum=osum+i;
ocount++;
}

}

cout<<"\n\nThe sum of even numbers is = "<<esum<<"\n\nCount of the even numbers is "<<ecount;
cout<<"\n\nThe sum of odd numbers is = "<<osum<<"\n\nCount of the odd numbers is "<<ocount;

return 0;
}

Previous
Next Post »