C++ programming language part- 79 Programming Logic and Technique
Programming
Logic and Technique:
int a;
display " Type a number";
accept a;
if((a!=0)&&(a%2==0))
display " The number is Even";
else { if(a==0) {display " The number is Zero "; }
if(a%2!=0) { " The number is
Odd "; }}
Or
if((a!=0)&&(a%2==0))
display " The number is Even";
else { if(a==0) { display " The number is Zero "; }
else display
" The number is Odd "; }
Or
if((a!=0)&&(a%2==0))
display " The number is Even";
else if(a==0) display" The
number is Zero ";
else display " The number is
Odd ";
Or
if((a!=0)&&(a%2==0))
display " The number is Even";
else if(a==0) display " The
number is Zero ";
else if(a%2!=0) display " The
number is Odd ";
Program Ex_9_11
#include
void main()
{
int a;
cout<<" Type a number,
please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is
Even"<
else
{
if(a==0)
{
cout<<"
The number is Zero "<
}
if(a%2!=0)
{
cout<<"
The number is Odd "<
}
}
}
Program EX_9_12
#include
void main()
{
int a;
cout<<" Type a number,
please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is
Even"<
else
{
if(a==0)
{
cout<<"
The number is Zero "<
}
else
cout<<"
The number is Odd "<
}
}
Program Ex_9_13
#include
void main()
{
int a;
cout<<" Type a number,
please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is
Even"<
else if(a==0)
cout<<"
The number is Zero "<
else
cout<<"
The number is Odd "<
}
Program Ex_9_14
#include
void main()
{
int a;
cout<<" Type a number,
please "<
cin>>a;
if((a!=0)&&(a%2==0))
cout<<" The number is
Even"<
else if(a==0)
cout<<"
The number is Zero "<
else if(a%2!=0)
cout<<"
The number is Odd "<
}
Program Ex_9_2
#include
void main()
{
char type;
int
size;
cout<<"
Type the color of your Television(B/C) ? ";
cin>>type;
if (type=='B')
cout<<"You
will get 5% discount "<
else
cout<<"Color?, type size in inches
";
cin>>size;
{
if(size==14)
cout<<"You
will get 10% discount "<
else
cout<<"You
will get 15% discount "<
}
}
Program Ex_9_3
#include
void main()
{
int p;
cout<<"
Type your year,please "<
cin>>p;
if(((p%4==0)&&(p%100!=0))||(p%400==0))
cout<<"The Year is Leap
year"<
else
cout<<"The
Year is not leap Year";
}
Program Ex_9_4_1
#include
void main()
{
int
p1,p2,p3;
cout<<"
Type first number, please
"<
cin>>p1;
cout<<"
Type second number, please "<
cin>>p2;
cout<<"
Type first number, please
"<
cin>>p3;
if(p1>p2)
{
if(p1>p3)
cout<<"The largest number is
"<
else
cout<<"The largest number is
"<
}
else
{
if(p2>p3)
cout<<"The largest number is
"<
else
cout<<"The largest number is
"<
}
}
Alternate
Program 9_4_2
#include
void main()
{
int
p1,p2,p3;
int high;
cout<<"
Type first number, please
"<
cin>>p1;
cout<<"
Type second number, please "<
cin>>p2;
cout<<"
Type first number, please
"<
cin>>p3;
if(p1>p2)
high=p1;
else
high=p2;
if(p3>high)
cout<<"The largest number is "<
else
cout<<"The
largest number is "<
}
Program Ex_9_5
#include
void main()
{
int
p1,p2,reminder;
cout<<"
Type first number, please
"<
cin>>p1;
cout<<"
Type second number, please "<
cin>>p2;
if(((p2!=0)&&(p2>0))&&(p2>p1))
{
reminder=p1%p2;
}
else
cout<<"Sorry
man! ";
}