SlideShare una empresa de Scribd logo
1 de 12
1. Program to swap two values using third variable.
2. Program to swap two values without using third variable.
3. Program to find the maximum of 10 values stored in array.
4. Program to find the smallest of 10 values stored in array.
5. Program to find the largest of two values using conditional
operator.
6.Program to find the smallest of three values using conditional
operator.
#include<iostream.h>
#include<conio.h>
void main()
{
 int a,b,temp;                                       OUTPUT
 clrscr();                                   Enter value of a: 45
cout<<“Enter value of a:”;                   Enter value of b: 56
cin>>a;                                      Original value of a is:45
cout<<“Enter value of b:”;                   Original value of b is:56
cin>>b;                                      After Swapping
 cout<<"Original value of a is:"<<a<<endl;   New value of a is:56
 cout<<"Original value of b is:"<<b<<endl;   New value of b is:45
temp=a;
 a=b;
 b=temp;
cout<<“After Swapping..”<<endl;
 cout<<“New value of a is:"<<a<<endl;
 cout<<“New value of b is:"<<b<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
class swapping
{
 public:
 int anew,bnew,temp;
 void swap( int anew, int bnew) //function receives arguments via object of swapping class
 {
  temp=anew;
  anew=bnew;
  bnew=temp;                                                                                         Output
  cout<<“New value of a is:"<<anew<<endl;                                                    Value of a is: 10
  cout<<“New value of b is:"<<bnew<<endl;
}                                                                                            Value of b is: 15
};                                                                                           After swapping
void main()
{                                                                                            New Value of a is: 15
 int a=10,b=15; //we have set the values of a and b as 10 ,15, it can be user defined too.   New value of b is: 10
clrscr();
 swapping s1; //created object of swapping class
 cout<<“Value of a is:"<<a<<endl;
 cout<<“Value of b is:"<<b<<endl;
cout<<“After Swapping”<<endl;
 s1.swap(a,b); //called swap function using object and dot operator
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
 int a, b;                                      OUTPUT
 clrscr();                              Enter value of a: 45
cout<<“Enter value of a:”;              Enter value of b: 56
cin>>a;                                 Original value of a is:45
cout<<“Enter value of b:”;              Original value of b is:56
cin>>b;                                 After Swapping
 cout<<“Value of a is:"<<a<<endl;       New value of a is:56
 cout<<“Value of b is:"<<b<<endl;       New value of b is:45
 a=a+b;;
 b=a-b;
 a=a-b;
cout<<“After Swapping..”<<endl;
 cout<<“New value of a is:"<<a<<endl;
 cout<<“New value of b is:"<<b<<endl;
getch();
}
2.Program to swap two values without using third variable.
    #include<iostream.h>
    #include<conio.h>
    class swapping
    {
     public:
     int anew,bnew;
     void swap( int anew, int bnew);
     };
     void swapping :: swap(int anew , int bnew)
     {
      anew= anew+bnew;                                        OUTPUT
      bnew=anew-bnew;                             Enter value of a: 25
      anew=anew-bnew;                             Enter value of b: 65
      cout<<"new value of a is:"<<anew<<endl;     Value of a is: 25
      cout<<"new value of b is:"<<bnew<<endl;
                                                   Value of b is:65
     }
    void main()                                   After swapping
    {                                             Value of a is: 65
     int a,b;                                     Value of b is: 25
     clrscr();
     swapping s1,s2;
     cout<<"Enter value of a:";
     cin>>a;
     cout<<"Enter value of b:";
     cin>>b;
     cout<<“Value of a is:"<<a<<endl;
     cout<<“Value of b is:"<<b<<endl;
     s1.swap(a,b);
      getch();
    }
3.Program to find maximum of 10 values stored in array.

     #include<iostream.h>
     #include<conio.h>
     void main()
     {
     int a[10],i,j,m,loc=0;
                                                           OUTPUT
     clrscr();                              Enter 10 elements of array:
     cout<<"enter 10 elements of array:";                                  5
     for(i=0;i<=9;i++)                                                     8
     {
      cin>>a[i];                                                           2
     }                                                                    12
     m=a[0];                                                              65
     for(j=1;j<=9;j++)
     {
                                                                           36
      if(a[j]>m)                                                          98
      {                                                                   45
       m=a[j];                                                            25
       loc=j+1;
      }                                                                   96
     }
     cout<<"max value is:"<<m;              Max value is: 98
     cout<<"its loc is:"<<loc;
     getch();
                                             Its location is: 7
     }
3.Program to find maximum of 10 values stored in array.
    #include<iostream.h>                                                                            OUTPUT
    #include<conio.h>
    class greatest
    {
      public:
      int a[10],j,max;
      int largest() //member func of greatest class that returns a value of integer type
 
 
       {
       cout<<"enter 10 elements of array:";
                                                                                            Enter 10 elements of array:
      for(int i=0;i<=9;i++)                                                                                           5
      {
       cin>>a[i];                                                                                                     8
      }
       max=a[0];                                                                                                      2
       for(j=1;j<=9;j++)
       {                                                                                                            12
 
 
         if(a[j]>max)
         {
                                                                                                                     65
          max=a[j];                                                                                                 36
        }
      }                                                                                                             98
      return max;
     }                                                                                                              45
    };
    void main()                                                                                                     25
 
 
     {
     int max1;
                                                                                                                     96
    clrscr();
    greatest g1;
    max1=g1.largest();                                                                     Max value is: 98
    cout<<"Greatest of ten values is:"<<max1;
    getch();
    }
4.Program to find smallest of 10 values stored in an array.
   #include<iostream.h>
   #include<conio.h>
   void main()
   {
    int min,a[10],I;                                   OUTPUT
   clrscr();                                 Enter 10 elements of array:
   cout<<“Enter 10 elements of array.”;                                      5
   for(i=0;i<=9;i++)                                                         8
   cin>>a[i];                                                                2
                                                                             12
   for(j=1;j<=9;j++)                                                        65
   {                                                                        36
     If(a[j]<min)                                                           98
     min=a[j];                                                              45
   }                                                                        25
   cout<<“smallest of 10 values is:”<<min;                                  96
   getch();
                                              Smallest of ten values is: 2
   }
4.program to find smallest of 10 values stored in an array.
   #include<iostream.h>
   #include<conio.h>
   class smallest
   {
     public:
     int a[10],j,min;                                                     OUTPUT
     int calculate_smallest()
     {                                                           Enter 10 elements of array:
     cout<<"enter 10 elements of array:";
     for(int i=0;i<=9;i++)                                                                 -5
     {
      cin>>a[i];                                                                            8


      }
       min=a[0];         //0th element is set as minimum values
                                                                                             2
      for(j=1;j<=9;j++)                                                                   12
      {
       if(a[j]<min)                                                                       65
       {
         min=a[j];                                                                        36
       }
     }                                                                                    98

    }
      return min;                                                                          45
   };                                                                                     25
   void main()
   {                                                                                      96
   int min1;
   clrscr();
   smallest s1;
   min1=s1.calculate_smallest();
                                                                  Smallest of ten values is: -5
   cout<<“Smallest of ten values is:"<<min1;
   getch();
   }
5.Program to find largest of two values using conditional operator.
  #include<iostream.h>
  #include<conio.h>
  void main()
 {
  int a , b, c;                           OUTPUT
                                           Enter value of a: 56
  clrscr();                               Enter value of b: 36
  cout<<“Enter value of a:”;              56 is greatest.
  cin>>a;
  cout<<“ Enter value of b:”;
  cin>>b;
  c=a>b?a:b; //using conditional operator, c stores the
  biggest of two values.
 cout<<a<<“ is greatest”;
 getch();
}
5.Program to find greatest of two values using conditional
operator.
      #include<iostream.h>
      #include<conio.h>
      class comparison
      {
         public:
          int a1,b1,max;
         int greatest (int a1,int b1)
         {
          max=a1>b1?a1:b1; //using conditional(ternary operator) to compare a and b, storing result in max.
          return max;
         }
      };
      void main()
      {
      int a, b;
      clrscr();                                                               OUTPUT
      cout<<"enter a:";
      cin>>a;
      cout<<"enter b:";
      cin>>b;                                                     Enter value of a: 62
      comparison c1;                                              Enter value of b: 36
      cout<<"Greatest of two values is:"<<c1.greatest(a,b);
      getch();
                                                                   Greatest of two values is:62
      }
6.Program to find smallest of three values using ternary operator.
     #include<iostream.h>
     #include<conio.h>
     void main()
     {                                          OUTPUT
      int a , b, c, max;           Enter value of a: 96
     clrscr();                     Enter value of b: 125
     cout<<"Enter value of a:";    Enter value of c: 36
     cin>>a;                       36 is greatest
     cout<<" Enter value of b:";
     cin>>b;
     cout<<"Enter value of c:";
     cin>>c;
      max=a<b?(a<c?a:c):(b<c?b:c); //using conditional
      operator, max stores the biggest of three values.
     cout<<max<<" is smallest";
     getch();
    }

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

C++11
C++11C++11
C++11
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
C++ book
C++ bookC++ book
C++ book
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C++11
C++11C++11
C++11
 
basics of c++
basics of c++basics of c++
basics of c++
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
C++
C++C++
C++
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 

Destacado

Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
Effective writing, tips for Bloggers
Effective writing, tips for BloggersEffective writing, tips for Bloggers
Effective writing, tips for BloggersAhmad Idrees
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer SystemAhmad Idrees
 
Principle of marketing
Principle of marketing Principle of marketing
Principle of marketing Ahmad Idrees
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of businessAhmad Idrees
 
What is computer Introduction to Computing
What is computer Introduction  to Computing What is computer Introduction  to Computing
What is computer Introduction to Computing Ahmad Idrees
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer VisionBrian Thorne
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessmanAhmad Idrees
 
An overview of computers and programming languages
An overview of computers and programming languages An overview of computers and programming languages
An overview of computers and programming languages Ahmad Idrees
 
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDWhats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDDavid Ware
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Strategic planning and mission statement
Strategic planning and mission statement Strategic planning and mission statement
Strategic planning and mission statement Ahmad Idrees
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput Ahmad Idrees
 

Destacado (20)

Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Effective writing, tips for Bloggers
Effective writing, tips for BloggersEffective writing, tips for Bloggers
Effective writing, tips for Bloggers
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer System
 
Principle of marketing
Principle of marketing Principle of marketing
Principle of marketing
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of business
 
What is business
What is businessWhat is business
What is business
 
What is computer Introduction to Computing
What is computer Introduction  to Computing What is computer Introduction  to Computing
What is computer Introduction to Computing
 
Python in Computer Vision
Python in Computer VisionPython in Computer Vision
Python in Computer Vision
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessman
 
An overview of computers and programming languages
An overview of computers and programming languages An overview of computers and programming languages
An overview of computers and programming languages
 
IBM MQ V9 Overview
IBM MQ V9 OverviewIBM MQ V9 Overview
IBM MQ V9 Overview
 
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CDWhats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
Whats new in IBM MQ; V9 LTS, V9.0.1 CD and V9.0.2 CD
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Strategic planning and mission statement
Strategic planning and mission statement Strategic planning and mission statement
Strategic planning and mission statement
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 

Similar a Basic c++ programs

Similar a Basic c++ programs (20)

C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
C++ practical
C++ practicalC++ practical
C++ practical
 
C++ file
C++ fileC++ file
C++ file
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Oop1
Oop1Oop1
Oop1
 
cpp promo ppt.pptx
cpp promo ppt.pptxcpp promo ppt.pptx
cpp promo ppt.pptx
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Notes
NotesNotes
Notes
 

Más de harman kaur

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black treeharman kaur
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.harman kaur
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gateharman kaur
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)harman kaur
 
Rules of inference
Rules of inferenceRules of inference
Rules of inferenceharman kaur
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++harman kaur
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornicsharman kaur
 

Más de harman kaur (14)

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black tree
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Digital u1
Digital u1Digital u1
Digital u1
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
 
Msql query
Msql queryMsql query
Msql query
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
 
Virtual function
Virtual functionVirtual function
Virtual function
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
 

Último

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Basic c++ programs

  • 1. 1. Program to swap two values using third variable. 2. Program to swap two values without using third variable. 3. Program to find the maximum of 10 values stored in array. 4. Program to find the smallest of 10 values stored in array. 5. Program to find the largest of two values using conditional operator. 6.Program to find the smallest of three values using conditional operator.
  • 2. #include<iostream.h> #include<conio.h> void main() { int a,b,temp; OUTPUT clrscr(); Enter value of a: 45 cout<<“Enter value of a:”; Enter value of b: 56 cin>>a; Original value of a is:45 cout<<“Enter value of b:”; Original value of b is:56 cin>>b; After Swapping cout<<"Original value of a is:"<<a<<endl; New value of a is:56 cout<<"Original value of b is:"<<b<<endl; New value of b is:45 temp=a; a=b; b=temp; cout<<“After Swapping..”<<endl; cout<<“New value of a is:"<<a<<endl; cout<<“New value of b is:"<<b<<endl; getch(); }
  • 3. #include<iostream.h> #include<conio.h> class swapping { public: int anew,bnew,temp; void swap( int anew, int bnew) //function receives arguments via object of swapping class { temp=anew; anew=bnew; bnew=temp; Output cout<<“New value of a is:"<<anew<<endl; Value of a is: 10 cout<<“New value of b is:"<<bnew<<endl; } Value of b is: 15 }; After swapping void main() { New Value of a is: 15 int a=10,b=15; //we have set the values of a and b as 10 ,15, it can be user defined too. New value of b is: 10 clrscr(); swapping s1; //created object of swapping class cout<<“Value of a is:"<<a<<endl; cout<<“Value of b is:"<<b<<endl; cout<<“After Swapping”<<endl; s1.swap(a,b); //called swap function using object and dot operator getch(); }
  • 4. #include<iostream.h> #include<conio.h> void main() { int a, b; OUTPUT clrscr(); Enter value of a: 45 cout<<“Enter value of a:”; Enter value of b: 56 cin>>a; Original value of a is:45 cout<<“Enter value of b:”; Original value of b is:56 cin>>b; After Swapping cout<<“Value of a is:"<<a<<endl; New value of a is:56 cout<<“Value of b is:"<<b<<endl; New value of b is:45 a=a+b;; b=a-b; a=a-b; cout<<“After Swapping..”<<endl; cout<<“New value of a is:"<<a<<endl; cout<<“New value of b is:"<<b<<endl; getch(); }
  • 5. 2.Program to swap two values without using third variable.  #include<iostream.h>  #include<conio.h>  class swapping  {  public:  int anew,bnew;  void swap( int anew, int bnew);  };  void swapping :: swap(int anew , int bnew)  {  anew= anew+bnew; OUTPUT  bnew=anew-bnew; Enter value of a: 25  anew=anew-bnew; Enter value of b: 65  cout<<"new value of a is:"<<anew<<endl; Value of a is: 25  cout<<"new value of b is:"<<bnew<<endl; Value of b is:65  }  void main() After swapping  { Value of a is: 65  int a,b; Value of b is: 25  clrscr();  swapping s1,s2;  cout<<"Enter value of a:";  cin>>a;  cout<<"Enter value of b:";  cin>>b;  cout<<“Value of a is:"<<a<<endl;  cout<<“Value of b is:"<<b<<endl;  s1.swap(a,b);  getch();  }
  • 6. 3.Program to find maximum of 10 values stored in array.  #include<iostream.h>  #include<conio.h>  void main()  {  int a[10],i,j,m,loc=0; OUTPUT  clrscr(); Enter 10 elements of array:  cout<<"enter 10 elements of array:"; 5  for(i=0;i<=9;i++) 8  {  cin>>a[i]; 2  } 12  m=a[0]; 65  for(j=1;j<=9;j++)  { 36  if(a[j]>m) 98  { 45  m=a[j]; 25  loc=j+1;  } 96  }  cout<<"max value is:"<<m; Max value is: 98  cout<<"its loc is:"<<loc;  getch(); Its location is: 7  }
  • 7. 3.Program to find maximum of 10 values stored in array.  #include<iostream.h> OUTPUT  #include<conio.h>  class greatest  {  public:  int a[10],j,max;  int largest() //member func of greatest class that returns a value of integer type   { cout<<"enter 10 elements of array:"; Enter 10 elements of array:  for(int i=0;i<=9;i++) 5  {  cin>>a[i]; 8  }  max=a[0]; 2  for(j=1;j<=9;j++)  { 12   if(a[j]>max) { 65  max=a[j]; 36  }  } 98  return max;  } 45  };  void main() 25   { int max1; 96  clrscr();  greatest g1;  max1=g1.largest(); Max value is: 98  cout<<"Greatest of ten values is:"<<max1;  getch();  }
  • 8. 4.Program to find smallest of 10 values stored in an array.  #include<iostream.h>  #include<conio.h>  void main()  {  int min,a[10],I; OUTPUT  clrscr(); Enter 10 elements of array:  cout<<“Enter 10 elements of array.”; 5  for(i=0;i<=9;i++) 8  cin>>a[i]; 2 12  for(j=1;j<=9;j++) 65  { 36  If(a[j]<min) 98  min=a[j]; 45  } 25  cout<<“smallest of 10 values is:”<<min; 96  getch(); Smallest of ten values is: 2  }
  • 9. 4.program to find smallest of 10 values stored in an array.  #include<iostream.h>  #include<conio.h>  class smallest  {  public:  int a[10],j,min; OUTPUT  int calculate_smallest()  { Enter 10 elements of array:  cout<<"enter 10 elements of array:";  for(int i=0;i<=9;i++) -5  {  cin>>a[i]; 8   } min=a[0]; //0th element is set as minimum values 2  for(j=1;j<=9;j++) 12  {  if(a[j]<min) 65  {  min=a[j]; 36  }  } 98   } return min; 45  }; 25  void main()  { 96  int min1;  clrscr();  smallest s1;  min1=s1.calculate_smallest(); Smallest of ten values is: -5  cout<<“Smallest of ten values is:"<<min1;  getch();  }
  • 10. 5.Program to find largest of two values using conditional operator.  #include<iostream.h>  #include<conio.h>  void main() {  int a , b, c; OUTPUT Enter value of a: 56  clrscr(); Enter value of b: 36  cout<<“Enter value of a:”; 56 is greatest.  cin>>a;  cout<<“ Enter value of b:”;  cin>>b;  c=a>b?a:b; //using conditional operator, c stores the biggest of two values.  cout<<a<<“ is greatest”;  getch(); }
  • 11. 5.Program to find greatest of two values using conditional operator.  #include<iostream.h>  #include<conio.h>  class comparison  {  public:  int a1,b1,max;  int greatest (int a1,int b1)  {  max=a1>b1?a1:b1; //using conditional(ternary operator) to compare a and b, storing result in max.  return max;  }  };  void main()  {  int a, b;  clrscr(); OUTPUT  cout<<"enter a:";  cin>>a;  cout<<"enter b:";  cin>>b; Enter value of a: 62  comparison c1; Enter value of b: 36  cout<<"Greatest of two values is:"<<c1.greatest(a,b);  getch(); Greatest of two values is:62  }
  • 12. 6.Program to find smallest of three values using ternary operator.  #include<iostream.h>  #include<conio.h>  void main()  { OUTPUT  int a , b, c, max; Enter value of a: 96  clrscr(); Enter value of b: 125  cout<<"Enter value of a:"; Enter value of c: 36  cin>>a; 36 is greatest  cout<<" Enter value of b:";  cin>>b;  cout<<"Enter value of c:";  cin>>c;  max=a<b?(a<c?a:c):(b<c?b:c); //using conditional operator, max stores the biggest of three values.  cout<<max<<" is smallest";  getch(); }

Notas del editor

  1. This is a program to swap two values using the third variable(temp). It does not use the class concept.The next program is same but it is done using class concept.
  2. This is same program as the previous one, but it use class structre.
  3. It is a program to swap two values without using third variable and without using class structure