Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sum of EVEN & ODD number

Program print Addition(sum) of Even number & Odd number. User can define the starting and ending value (so enjoy)


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

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)