際際滷

際際滷Share a Scribd company logo
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
comscicomscicomscicomscicomscicomsci
PROJECT in COSC 60
Data Structure
Jenelyn B. Pa単oso
BSCS II
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:
 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:
 MASS 
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int a,b,c,gram;
float d,e,f;
cout<<Enter GRAM: ;
cin>>gram;
a= 1000*gram;
b= 100*gram;
c= 10*gram;
d= 0.1*gram;
e= 0.01*gram;
f= 0.001*gram;
cout<<Milligramt= <<a;
cout<<nCentigramt= <<b;
cout<<nDecigramt= <<c;
cout<<nDecagramt= <<d;
cout<<nHectogramt= <<e;
cout<<nKilogramt= <<f;
getch( );
return 0;
}
OUTPUT:
 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:
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:
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:
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:
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:
WHILE LOOP STATEMENT
 SQUARED and CUBE 
CODES:
#include<iostream.h>
#include<conio.h>
#include<dos.h>
main( )
{
clrscr( );
int n,s,c;
cout<<" SQUARED CUBE";
n=1;
while(n<=10){
cout<<"n"<<n;
s=n*n;
cout<<"t"<<s;
c=n*n*n;
cout<<"t"<<c;
n++;
delay(1000);
}
return 0;
getch( );
}
OUTPUT:
DO-WHILE LOOP STATEMENT
 MULTIPLICATION TABLE 
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
n1 = 1;
cout<<"ttttMULTIPLICATION
TABLEnn";
do{
cout<<"t"<<n1;
n1 +=1;
}
while(n1<=9);
cout<<"nn";
n2 = 2;
do{
cout<<"t"<<n2;
n2+=2;
}
while(n2<=18);
cout<<"nn";
n3=3;
do{
cout<<"t"<<n3;
n3 +=3;
}
while(n3<=27);
cout<<"nn";
n4 = 4;
do{
cout<<"t"<<n4;
n4 += 4;
}
while(n4<=36);
cout<<"nn";
n5 = 5;
do{
cout<<"t"<<n5;
n5 += 5;
}
while(n5<=45);
cout<<"nn";
n6 = 6;
do{
cout<<"t"<<n6;
n6 += 6;
}
while(n6<=54);
cout<<"nn";
n7 = 7;
do{
cout<<"t"<<n7;
n7 += 7;
}
while(n7<=63);
cout<<"nn";
n8 = 8;
do{
cout<<"t"<<n8;
n8 += 8;
}
while(n8<=72);
cout<<"nn";
n9 = 9;
do{
cout<<"t"<<n9;
n9+=9;
}
while(n9<=81);
cout<<"nn";
n10 = 10;
do{
cout<<"t"<<n10;
n10 += 10;
}
while(n10<=90);
getch( );
return 0;
}
OUTPUT:
FOR LOOP STATEMENT
 PYRAMID 
CODES:
#include<iostream.h>
#include<conio.h>
main( )
{
clrscr( );
int row, c, n, temp;
cout<<"Enter number of rows: ";
cin>>n;
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
cout<<" ";
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
cout<<"*";
cout<<"n";
}
getch( );
return 0;
}
OUTPUT:
Ad

Recommended

Chapter 10
Chapter 10
University of Calgary, School of Creative and Performing Arts
Lo39
Lo39
lksoo
Code Inventory
Code Inventory
Nick Harrison
Visual basic coding
Visual basic coding
Sara Corpuz
Interoduction to c++
Interoduction to c++
Amresh Raj
How to Work with Dev-C++
How to Work with Dev-C++
Deepak Jha
Payroll
Payroll
Shashi soni
Atm (bm)
Atm (bm)
Neha Patel
Example Programs of CPP programs ch 1.pptx
Example Programs of CPP programs ch 1.pptx
DrVikasMahor
C++ practical
C++ practical
Rahul juneja
Pads lab manual final
Pads lab manual final
AhalyaR
Chapter 3 Expressions and Inteactivity
Chapter 3 Expressions and Inteactivity
GhulamHussain142878
Oops lab manual
Oops lab manual
Vivek Kumar Sinha
Programming in C++
Programming in C++
Pooya Merat
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
C++ programming basics
C++ programming basics
Munazza-Mah-Jabeen
Oops practical file
Oops practical file
Ankit Dixit
Oop project
Oop project
Quratulain Naqvi
C++
C++
Prakash Sharma
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
abdurrahimk182
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
SanaullahAttariQadri
c++ lab manual
c++ lab manual
Shrunkhala Wankhede
Practical File of c++.docx lab manual program question
Practical File of c++.docx lab manual program question
vidhimangal05
C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
Atifkhilji
C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
C++ ch2
C++ ch2
Venkateswarlu Vuggam
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder

More Related Content

Similar to C++ Sample Codes (Data Structure) (20)

Example Programs of CPP programs ch 1.pptx
Example Programs of CPP programs ch 1.pptx
DrVikasMahor
C++ practical
C++ practical
Rahul juneja
Pads lab manual final
Pads lab manual final
AhalyaR
Chapter 3 Expressions and Inteactivity
Chapter 3 Expressions and Inteactivity
GhulamHussain142878
Oops lab manual
Oops lab manual
Vivek Kumar Sinha
Programming in C++
Programming in C++
Pooya Merat
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
C++ programming basics
C++ programming basics
Munazza-Mah-Jabeen
Oops practical file
Oops practical file
Ankit Dixit
Oop project
Oop project
Quratulain Naqvi
C++
C++
Prakash Sharma
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
abdurrahimk182
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
SanaullahAttariQadri
c++ lab manual
c++ lab manual
Shrunkhala Wankhede
Practical File of c++.docx lab manual program question
Practical File of c++.docx lab manual program question
vidhimangal05
C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
Atifkhilji
C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
C++ ch2
C++ ch2
Venkateswarlu Vuggam
Example Programs of CPP programs ch 1.pptx
Example Programs of CPP programs ch 1.pptx
DrVikasMahor
Pads lab manual final
Pads lab manual final
AhalyaR
Chapter 3 Expressions and Inteactivity
Chapter 3 Expressions and Inteactivity
GhulamHussain142878
Programming in C++
Programming in C++
Pooya Merat
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
Oops practical file
Oops practical file
Ankit Dixit
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
abdurrahimk182
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
SanaullahAttariQadri
Practical File of c++.docx lab manual program question
Practical File of c++.docx lab manual program question
vidhimangal05
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
Atifkhilji

Recently uploaded (20)

What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
Paper 108 | Thoreaus Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreaus Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
Overview of Employee in Odoo 18 - Odoo 際際滷s
Overview of Employee in Odoo 18 - Odoo 際際滷s
Celine George
Paper 109 | Archetypal Journeys in Interstellar: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in Interstellar: Exploring Universal Themes...
Rajdeep Bavaliya
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
Paper 108 | Thoreaus Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreaus Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
Overview of Employee in Odoo 18 - Odoo 際際滷s
Overview of Employee in Odoo 18 - Odoo 際際滷s
Celine George
Paper 109 | Archetypal Journeys in Interstellar: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in Interstellar: Exploring Universal Themes...
Rajdeep Bavaliya
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
Ad

C++ Sample Codes (Data Structure)

  • 1. comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci comscicomscicomscicomscicomscicomsci PROJECT in COSC 60 Data Structure Jenelyn B. Pa単oso BSCS II
  • 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:
  • 4. MASS CODES: #include<iostream.h> #include<conio.h> main( ) { clrscr( ); int a,b,c,gram; float d,e,f; cout<<Enter GRAM: ; cin>>gram; a= 1000*gram; b= 100*gram; c= 10*gram; d= 0.1*gram; e= 0.01*gram; f= 0.001*gram; cout<<Milligramt= <<a; cout<<nCentigramt= <<b; cout<<nDecigramt= <<c; cout<<nDecagramt= <<d; cout<<nHectogramt= <<e; cout<<nKilogramt= <<f; 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:
  • 10. WHILE LOOP STATEMENT SQUARED and CUBE CODES: #include<iostream.h> #include<conio.h> #include<dos.h> main( ) { clrscr( ); int n,s,c; cout<<" SQUARED CUBE"; n=1; while(n<=10){ cout<<"n"<<n; s=n*n; cout<<"t"<<s; c=n*n*n; cout<<"t"<<c; n++; delay(1000); } return 0; getch( ); } OUTPUT:
  • 11. DO-WHILE LOOP STATEMENT MULTIPLICATION TABLE CODES: #include<iostream.h> #include<conio.h> main( ) { clrscr( ); int n1,n2,n3,n4,n5,n6,n7,n8,n9,n10; n1 = 1; cout<<"ttttMULTIPLICATION TABLEnn"; do{ cout<<"t"<<n1; n1 +=1; } while(n1<=9); cout<<"nn"; n2 = 2; do{ cout<<"t"<<n2; n2+=2; } while(n2<=18); cout<<"nn"; n3=3; do{ cout<<"t"<<n3; n3 +=3; } while(n3<=27); cout<<"nn"; n4 = 4; do{ cout<<"t"<<n4; n4 += 4; } while(n4<=36); cout<<"nn"; n5 = 5; do{ cout<<"t"<<n5; n5 += 5; } while(n5<=45); cout<<"nn"; n6 = 6; do{ cout<<"t"<<n6; n6 += 6; } while(n6<=54); cout<<"nn"; n7 = 7; do{ cout<<"t"<<n7; n7 += 7; } while(n7<=63); cout<<"nn"; n8 = 8; do{ cout<<"t"<<n8; n8 += 8; } while(n8<=72);
  • 12. cout<<"nn"; n9 = 9; do{ cout<<"t"<<n9; n9+=9; } while(n9<=81); cout<<"nn"; n10 = 10; do{ cout<<"t"<<n10; n10 += 10; } while(n10<=90); getch( ); return 0; } OUTPUT:
  • 13. FOR LOOP STATEMENT PYRAMID CODES: #include<iostream.h> #include<conio.h> main( ) { clrscr( ); int row, c, n, temp; cout<<"Enter number of rows: "; cin>>n; temp = n; for ( row = 1 ; row <= n ; row++ ) { for ( c = 1 ; c < temp ; c++ ) cout<<" "; temp--; for ( c = 1 ; c <= 2*row - 1 ; c++ ) cout<<"*"; cout<<"n"; } getch( ); return 0; } OUTPUT: