Brijmohan lal Sahu - Facebook
ads
ads

Sunday, November 16, 2014

Program to count number of even & odd numbers in a given range using conditional operator in C++.


even odd using conditional operator


Code Box
---------------------------------------------

/* Program to count number of even & odd numbers in a given range*/
/*Counts Including starting and ending integer */

#include<iostream.h>
#include<conio.h>
void main()
{
int start,end,even,odd,i;
clrscr();
even=0;
odd=0;

cout<<"\nEnter start :";
cin>>start;

cout<<"\nEnter end:";
cin>>end;

for(i=start;i<=end;i++)
{
(i%2==0)?even++:odd++;
}

cout<<"\n"<<even<<" even & "<<odd<<" odd numbers are present in between "<<start<<" & "<<end;

getch();
}

No comments:

Post a Comment