Code Box
---------------------------------------------
/*program to find even odd using conditional operator */
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
clrscr();
cout<<"\nEven Odd Checker ";
cout<<"\nEnter a number:";
cin>>num;
(num%2==0)?cout<<"\nEven Number":cout<<"\nOdd Number";
getch();
}
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();
}
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();
}
Code Box
---------------------------------------------
/*Program to find length or numbers of digits in any number*/
#include<iostream.h>
#include<conio.h>
void main()
{
int num,len;
len=0;
clrscr();
cout<<"\nEnter A Number :";
cin>>num;
do{
num=num/10;
len++;
}
while(num>=1);
cout<<"\nLength Number:"<<len;
getch();
}
/* Note: Due to the range of integer program does not work for more than 5 digits */
Code Box
---------------------------------------------
/*Program to find length or numbers of digits in any number*/
#include<iostream.h>
#include<conio.h>
void main()
{
int num,len;
clrscr();
cout<<"\nEnter A Number :";
cin>>num;
for(len=0;num>=1;)
{
num=num/10;
len++;
}
cout<<"\nLength Number:"<<len;
getch();
}
/* Note: Due to the range of integer program does not work for more than 5 digits */