Brijmohan lal Sahu - Facebook
ads
ads
Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Sunday, November 16, 2014

Program to find even odd using conditional operator in C++.


even odd


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();
}



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();
}

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

even odd in range


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();
}


Program to find length or numbers of digits in any number using do while loop in C++.

length of digit by do while loop


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 */

Program to find length or numbers of digits in any number using for loop in C++.



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 */