Code Box
--------------------------------------------
/* Program to count number of even & odd numbers in a given range*/
#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++)
{
if(i%2==0)
{even++;
}
else{
odd++;
}
}
cout<<"\n"<<even<<" even & "<<odd<<" odd numbers are present in between "<<start<<" & "<<end;
getch();
}
No comments:
Post a Comment