SOURCE CODE OUTPUT
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,osum=0,esum=0;
cout<<"Enter the number ";
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==0)
esum+=i;
else
osum+=i;
}
cout<<"Sum of odd numbers = "<<osum<<endl;
cout<<"Sum of even numbers = "<<esum;
return 0;
}
#include<math.h>
using namespace std;
int main()
{
int n,osum=0,esum=0;
cout<<"Enter the number ";
cin>>n;
for(int i=1;i<=n;i++)
{
if(i%2==0)
esum+=i;
else
osum+=i;
}
cout<<"Sum of odd numbers = "<<osum<<endl;
cout<<"Sum of even numbers = "<<esum;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment