SlideShare a Scribd company logo
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();
    }
Ad

More Related Content

What's hot (20)

C++11
C++11C++11
C++11
Quang Trần Duy
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
Geeks Anonymes
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
ForwardBlog Enewzletter
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
Bartlomiej Filipek
 
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)
Sumant Tambe
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
CyberPlusIndia
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
C++ book
C++ bookC++ book
C++ book
mailmerk
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan Rüegg
 
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]
Chris Adamson
 
C++11
C++11C++11
C++11
Sasha Goldshtein
 
basics of c++
basics of c++basics of c++
basics of c++
gourav kottawar
 
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
Matthieu Garrigues
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
HalaiHansaika
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
Waqar Younis
 
C++
C++C++
C++
VishalMishra313
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
Open Gurukul
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
zindadili
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
Thooyavan Venkatachalam
 

Viewers also liked (20)

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 Bloggers
Ahmad Idrees
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer System
Ahmad 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 Language
Ahmad Idrees
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of business
Ahmad Idrees
 
What is business
What is businessWhat is business
What is business
Ahmad 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 Vision
Brian Thorne
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessman
Ahmad 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
 
IBM MQ V9 Overview
IBM MQ V9 OverviewIBM MQ V9 Overview
IBM MQ V9 Overview
MarkTaylorIBM
 
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
David Ware
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
Ahmad Idrees
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
Ahmad Idrees
 
C++ ppt
C++ pptC++ ppt
C++ ppt
Aneesh Gupta
 
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
 
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 Bloggers
Ahmad Idrees
 
System outputs - Computer System
System outputs - Computer SystemSystem outputs - Computer System
System outputs - Computer System
Ahmad 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 Language
Ahmad Idrees
 
Basic characteristics of business
Basic characteristics of businessBasic characteristics of business
Basic characteristics of business
Ahmad 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 Vision
Brian Thorne
 
Basic qualities of a good businessman
Basic qualities of a good businessmanBasic qualities of a good businessman
Basic qualities of a good businessman
Ahmad 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 CD
David Ware
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
Ahmad 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
 
Ad

Similar to Basic c++ programs (20)

C- Programs - Harsh
C- Programs - HarshC- Programs - Harsh
C- Programs - Harsh
Harsh Sharma
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
C++ file
C++ fileC++ file
C++ file
simarsimmygrewal
 
Cpp programs
Cpp programsCpp programs
Cpp programs
harman kaur
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
Oop1
Oop1Oop1
Oop1
Vaibhav Bajaj
 
cpp promo ppt.pptx
cpp promo ppt.pptxcpp promo ppt.pptx
cpp promo ppt.pptx
C++ Homework Help
 
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
ssuser3cbb4c
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
Koshy Geoji
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
Yashpatel821746
 
7720
77207720
7720
Yashpatel821746
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
Andrey Karpov
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
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
premrings
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
Notes
NotesNotes
Notes
Hitesh Wagle
 
Ad

More from harman kaur (14)

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
harman 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 tree
harman kaur
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman 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
 
Digital u1
Digital u1Digital u1
Digital u1
harman kaur
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
harman 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
 
Msql query
Msql queryMsql query
Msql query
harman kaur
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
harman kaur
 
Virtual function
Virtual functionVirtual function
Virtual function
harman 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 electornics
harman kaur
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
harman 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 tree
harman kaur
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman 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 Gate
harman 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 inference
harman kaur
 
Virtual function
Virtual functionVirtual function
Virtual function
harman 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 electornics
harman kaur
 

Recently uploaded (20)

World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 

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

Editor's Notes

  • #3: 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.
  • #4: This is same program as the previous one, but it use class structre.
  • #5: It is a program to swap two values without using third variable and without using class structure