Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int i,a,b,even,odd; even=odd=0;
cout<<"Sum of even and odd no. (by:Tarun Rawat)\n\n";
cout<<"Enter starting no. = ";
cin>>a;
cout<<"\nEnter last no. = ";
cin>>b;
for (i=a;i<=b;i++)
{ if(i%2==0)
even =even+i ;
else{odd =odd+i;}
}
cout<<"\nsum of even no. is = "<<even<<"\n"<<"sum of odd no. is = "<<odd;
getch();
}
No comments:
Post a Comment