Page

Saturday, 15 September 2018

program for finding sum of even and odd natural number

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int n,sum_even = 0, sum_odd = 0, ctr=1;
cout<<"uptu which natural number:";
cin>>n;
while(ctr <=n)
{
 if(ctr % 2 ==0)
 sum_even += ctr;
 else
 sum_odd+= ctr;
 ctr++;
}
cout<<"\n"<<"the sum of even integer is:"<< sum_even;
cout<<"\n"<<"the sum of odd integer is:"<< sum_odd;
getch();
return(0);
}



No comments:

Post a Comment