2. SIMPLE PROGRAMS
ARITHMETIC OPERATIONS
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int n1, n2, a, s, m;
float d;
cout<<“Enter two integersn”;
cin>>n1;
cin>>n2;
a = n1 + n2;
s = n1 - n2;
m = n1 * n2;
d = n1 / (float)n2;
cout<<“nSumt = “<<a;
cout<<“nDifference = “<<s;
cout<<“nProductt = “<<m;
cout<<“nQoutient = “<<d;
getch( );
return 0;
}
OUTPUT:
3. VOLUME OF CYLINDER
CODES:
#include<iostream.h>
#include<conio.h>
#define Pi 3.1416
main( )
{
clrscr( );
float VOLUME,radius,height;
cout<<“This program will compute the
VOLUME of CYLINDER with an input of
height and radius.n”;
cout<<“Enter radius of CYLINDER: “;
cin>>radius;
cout<<“Enter height of CYLINDER: “;
cin>>height;
VOLUME = Pi*height*radius*radius;
cout<<“nVOLUME:”<<VOLUME;
getch( );
return 0;
}
OUTPUT:
5. VOLUME OF A CONE
CODES:
#include<iostream.h>
#include<conio.h>
#define Pi 3.1416
main( )
{
clrscr( );
float VOLUME,radius,height;
cout<<“This program will compute the
VOLUME of CONE with an input of height
and radius.n”;
cout<<“Enter radius of CONE: “;
cin>>radius;
cout<<“Enter height of CONE: “;
cin>>height;
VOLUME =
Pi*height*radius+Pi*radius*radius;
cout<<“nVOLUME:”<<VOLUME;
getch( );
return 0;
}
OUTPUT:
6. IF ELSE STATEMENT
NEGATIVE OR POSITIVE
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int n;
cout<<"Enter a number: ";
cin>>n;
if(n>=0)
cout<<"POSITIVE";
else
cout<<"NEGATIVE";
getch( );
return 0;
}
OUTPUT:
7. NESTED IF ELSE STATEMENT
COMPARISON
CODES:
#include <iostream.h>
#include <conio.h>
main( )
{
clrscr( );
int num1 , num2;
cout<<"Enter two numbers:n";
cin>>num1>>num2;
if (num1>num2)
cout<<num1<<" is greater than "<<num2;
else if (num1<num2)
cout<<num1<<" is less than "<<num2;
else if (num1==num2)
cout<<num1<<" is equal to "<<num2;
else
cout<<"INVALID INPUT";
getch( );
return 0;
}
OUTPUT:
8. SWITCH-CASE STATEMENT
HOROSCOPE
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int z;
cout<<"[1] t ARIES t March 21 - April
19n[2] t TAURUS t April 20 - May
20n[3] t GEMINI t May 21 - June
20n[4] t CANCER t June 21 - July
22n[5] t LEO t t July 23 - August 22
n[6] t VIRGO t t August 23 -
September 22n[7] t LIBRA t t
September 23 - October 22n[8] t
SCORPIO t October 23 - November
21n[9] t SAGITTARIUS t November 22
- December 21n[10] t CAPRICON t
December 22 - January 19n[11] t
AQUARIUS t January 20 - February
18n[12] t PISCES t February 19 -
March 20nn";
cout<<"Choose your Zodiac Sign in
numbers from [1-12]: ";
cin>>z;
switch(z)
{
case 1:
cout<<"nARIES t March 21 - April
19nCharacteristics: Active, Demanding,
Determined, Effective, Ambitious";
break;
case 2:
cout<<"nTAURUS t April 20 - May
20nCharacteristics: Security, Subtle
strength, Appreciation, Instruction,
Patience";
break;
case 3:
cout<<"nGEMINI t May 21 - June
20nCharacteristics: Communication,
Indecision, Inquisitive, Intelligent,
Changeable";
break;
case 4:
cout<<"nCANCER t June 21 - July
22nCharacteristics: Emotion, Diplomatic,
Intensity, Impulsive, Selective";
break;
case 5:
cout<<"nLEO t July 23 - August 22
nCharacteristics: Ruling, Warmth,
Generosity, Faithful, Initiative";
break;
case 6:
cout<<"nVIRGO t August 23 -
September 22nCharacteristics:
Analyzing, Practical, Reflective,
Observation, Thoughtful";
break;
case 7:
9. cout<<"nLIBRA t September 23 -
October 22nCharacteristics: Balance,
Justice, Truth, Beauty, Perfection";
break;
case 8:
cout<<"nSCORPIO t October 23 -
November 21nCharacteristics:
Transient, Self-Willed, Purposeful,
Unyielding";
break;
case 9:
cout<<"nSAGITTARIUS t November 22 -
December 21nCharacteristics:
Philosophical, Motion, Experimentation,
Optimism";
break;
case 10:
cout<<"nCAPRICON t December 22 -
January 19nCharacteristics:
Determination, Dominance, Perservering,
Practical, Willful";break;
case 11:
cout<<"nAQUARIUS t January 20 -
February 18nCharacteristics:
Knowledge, Humanitarian, Serious,
Insightful, Duplicitous";
break;
case 12:
cout<<"nPISCES t February 19 - March
20nCharacteristics: Fluctuation, Depth,
Imagination, Reactive, Indecisive";
break;
default:
cout<<"nINVALID INPUT";
}
getch( );
return 0;
}
OUTPUT: