SlideShare a Scribd company logo
Presented By- Harsh Sharma
C- Programs - Harsh
OUTPUT
Enter value of a: 45
Enter value of b: 56
Original value of a is:45
Original value of b is:56
After Swapping
New value of a is:56
New value of b is:45
Output
Value of a is: 10
Value of b is: 15
After swapping
New Value of a is: 15
New value of b is: 10
OUTPUT
Enter value of a: 45
Enter value of b: 56
Original value of a is:45
Original value of b is:56
After Swapping
New value of a is:56
New value of b is:45
 #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;
 bnew=anew-bnew;
 anew=anew-bnew;
 cout<<"new value of a is:"<<anew<<endl;
 cout<<"new value of b is:"<<bnew<<endl;
 }
 void main()
 {
 int a,b;
 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();
 }
OUTPUT
Enter value of a: 25
Enter value of b: 65
Value of a is: 25
Value of b is:65
After swapping
Value of a is: 65
Value of b is: 25
 #include<iostream.h>
 #include<conio.h>
 void main()
 {
 int a[10],i,j,m,loc=0;
 clrscr();
 cout<<"enter 10 elements of array:";
 for(i=0;i<=9;i++)
 {
 cin>>a[i];
 }
 m=a[0];
 for(j=1;j<=9;j++)
 {
 if(a[j]>m)
 {
 m=a[j];
 loc=j+1;
 }
 }
 cout<<"max value is:"<<m;
 cout<<"its loc is:"<<loc;
 getch();
 }
OUTPUT
Enter 10 elements of array:
5
8
2
12
65
36
98
45
25
96
Max value is: 98
Its location is: 7
 #include<iostream.h>
 #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:";
 for(int i=0;i<=9;i++)
 {
 cin>>a[i];
 }
 max=a[0];
 for(j=1;j<=9;j++)
 {
 if(a[j]>max)
 {
 max=a[j];
 }
 }
 return max;
 }
 };
 void main()
 {
 int max1;
 clrscr();
 greatest g1;
 max1=g1.largest();
 cout<<"Greatest of ten values is:"<<max1;
 getch();
 }
OUTPUT
Enter 10 elements of array:
5
8
2
12
65
36
98
45
25
96
Max value is: 98
 #include<iostream.h>
 #include<conio.h>
 void main()
 {
 int min,a[10],I;
 clrscr();
 cout<<“Enter 10 elements of array.”;
 for(i=0;i<=9;i++)
 cin>>a[i];
 for(j=1;j<=9;j++)
 {
 If(a[j]<min)
 min=a[j];
 }
 cout<<“smallest of 10 values is:”<<min;
 getch();
 }
OUTPUT
Enter 10 elements of array:
5
8
2
12
65
36
98
45
25
96
Smallest of ten values is: 2
 #include<iostream.h>
 #include<conio.h>
 class smallest
 {
 public:
 int a[10],j,min;
 int calculate_smallest()
 {
 cout<<"enter 10 elements of array:";
 for(int i=0;i<=9;i++)
 {
 cin>>a[i];
 }
 min=a[0]; //0th element is set as minimum values
 for(j=1;j<=9;j++)
 {
 if(a[j]<min)
 {
 min=a[j];
 }
 }
 return min;
 }
 };
 void main()
 {
 int min1;
 clrscr();
 smallest s1;
 min1=s1.calculate_smallest();
 cout<<“Smallest of ten values is:"<<min1;
 getch();
 }
OUTPUT
Enter 10 elements of array:
-5
8
2
12
65
36
98
45
25
96
Smallest of ten values is: -
5
 #include<iostream.h>
 #include<conio.h>
 void main()
 {
 int a , b, c;
 clrscr();
 cout<<“Enter value of a:”;
 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();
 }
OUTPUT
Enter value of a: 56
Enter value of b: 36
56 is greatest.
 #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();
 cout<<"enter a:";
 cin>>a;
 cout<<"enter b:";
 cin>>b;
 comparison c1;
 cout<<"Greatest of two values is:"<<c1.greatest(a,b);
 getch();
 }
OUTPUT
Enter value of a: 62
Enter value of b: 36
Greatest of two values is:62
 #include<iostream.h>
 #include<conio.h>
 void main()
 {
 int a , b, c, max;
 clrscr();
 cout<<"Enter value of a:";
 cin>>a;
 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();
 }
OUTPUT
Enter value of a: 96
Enter value of b: 125
Enter value of c: 36
36 is greatest

More Related Content

PDF
C++ TUTORIAL 5
Farhan Ab Rahman
 
DOCX
Cpp programs
harman kaur
 
PDF
C++ TUTORIAL 4
Farhan Ab Rahman
 
PDF
C++ TUTORIAL 1
Farhan Ab Rahman
 
PDF
Stl algorithm-Basic types
mohamed sikander
 
DOCX
Basic Programs of C++
Bharat Kalia
 
DOCX
C++ file
Mukund Trivedi
 
PDF
C++ TUTORIAL 10
Farhan Ab Rahman
 
C++ TUTORIAL 5
Farhan Ab Rahman
 
Cpp programs
harman kaur
 
C++ TUTORIAL 4
Farhan Ab Rahman
 
C++ TUTORIAL 1
Farhan Ab Rahman
 
Stl algorithm-Basic types
mohamed sikander
 
Basic Programs of C++
Bharat Kalia
 
C++ file
Mukund Trivedi
 
C++ TUTORIAL 10
Farhan Ab Rahman
 

What's hot (20)

PDF
C++ TUTORIAL 3
Farhan Ab Rahman
 
PDF
Project_Euler_No_104_Pandigital_Fibonacci_ends
? ?
 
PPT
C questions
mohamed sikander
 
PDF
C++ Programming - 2nd Study
Chris Ohk
 
PDF
C++ Programming - 4th Study
Chris Ohk
 
PDF
C++ Programming - 1st Study
Chris Ohk
 
PDF
C++ TUTORIAL 8
Farhan Ab Rahman
 
PDF
Implementing string
mohamed sikander
 
DOCX
C++ assignment
Zohaib Ahmed
 
PDF
C++ practical
Rahul juneja
 
PDF
C++ TUTORIAL 2
Farhan Ab Rahman
 
DOCX
C++ file
simarsimmygrewal
 
PDF
1 borland c++ 5.02 by aramse
Aram SE
 
PDF
C++ Programming - 3rd Study
Chris Ohk
 
PDF
C++ TUTORIAL 9
Farhan Ab Rahman
 
DOCX
Oop lab report
khasmanjalali
 
PDF
C++ TUTORIAL 7
Farhan Ab Rahman
 
PDF
Lecture 4
sajidpk92
 
C++ TUTORIAL 3
Farhan Ab Rahman
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
? ?
 
C questions
mohamed sikander
 
C++ Programming - 2nd Study
Chris Ohk
 
C++ Programming - 4th Study
Chris Ohk
 
C++ Programming - 1st Study
Chris Ohk
 
C++ TUTORIAL 8
Farhan Ab Rahman
 
Implementing string
mohamed sikander
 
C++ assignment
Zohaib Ahmed
 
C++ practical
Rahul juneja
 
C++ TUTORIAL 2
Farhan Ab Rahman
 
1 borland c++ 5.02 by aramse
Aram SE
 
C++ Programming - 3rd Study
Chris Ohk
 
C++ TUTORIAL 9
Farhan Ab Rahman
 
Oop lab report
khasmanjalali
 
C++ TUTORIAL 7
Farhan Ab Rahman
 
Lecture 4
sajidpk92
 
Ad

Viewers also liked (18)

PPTX
3Com 6000M-RCTL
savomir
 
PPTX
Evaluación de desempeño directivo UGEL Y DRE
JESUS NAPOLEON HUANCA MAMANI
 
PPTX
Presentacion dioscar ley de victima
dioscar ramones
 
PPTX
AQUAFAN Introduction - Watco Group
Bertus Bolknak
 
PPTX
Ozone layer
Khalid Mindalano
 
PPTX
Tugasan 4 amalan terbaik dala pembangun bandar mapan a155649 muhammad hazim b...
Muhammad Hazim Shamsul Zamri
 
PDF
Equipo#2 domingo trabajo_grupal _pdf
Lidia Melissa Escobar Cruz
 
PPTX
3Com 1698-110-000-6.02
savomir
 
PPTX
3Com 3C96100D-AMGT
savomir
 
PDF
Arquitectura islamica unidad v
auriangelis jimenez guzman
 
PPT
Marine Industry
jinnayperez
 
PDF
หลักสูตรสอนภาษาไทยในฐานะภาษาต่างประเทศ (ในต่างประเทศ)
G ''Pamiiz Porpam
 
PDF
Trait Theory
Renny OlaLa
 
PPTX
C Programming- Harsh Sharma
Harsh Sharma
 
PPT
Hispania
Remei Baldó Asensi
 
DOCX
Gem 7-20-green dream
ijcparish
 
PPTX
CMO Disrupt Sydney 2016
Grant Stewart
 
3Com 6000M-RCTL
savomir
 
Evaluación de desempeño directivo UGEL Y DRE
JESUS NAPOLEON HUANCA MAMANI
 
Presentacion dioscar ley de victima
dioscar ramones
 
AQUAFAN Introduction - Watco Group
Bertus Bolknak
 
Ozone layer
Khalid Mindalano
 
Tugasan 4 amalan terbaik dala pembangun bandar mapan a155649 muhammad hazim b...
Muhammad Hazim Shamsul Zamri
 
Equipo#2 domingo trabajo_grupal _pdf
Lidia Melissa Escobar Cruz
 
3Com 1698-110-000-6.02
savomir
 
3Com 3C96100D-AMGT
savomir
 
Arquitectura islamica unidad v
auriangelis jimenez guzman
 
Marine Industry
jinnayperez
 
หลักสูตรสอนภาษาไทยในฐานะภาษาต่างประเทศ (ในต่างประเทศ)
G ''Pamiiz Porpam
 
Trait Theory
Renny OlaLa
 
C Programming- Harsh Sharma
Harsh Sharma
 
Gem 7-20-green dream
ijcparish
 
CMO Disrupt Sydney 2016
Grant Stewart
 
Ad

Similar to C- Programs - Harsh (20)

PPTX
Basic c++ programs
harman kaur
 
DOC
Pads lab manual final
AhalyaR
 
DOCX
C++ file
Mukund Trivedi
 
DOCX
basic programs in C++
Arun Nair
 
PPTX
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
PDF
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
PDF
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
DOCX
Bijender (1)
Ankush Kumar
 
PPT
Oop1
Vaibhav Bajaj
 
PDF
Final DAA_prints.pdf
Yashpatel821746
 
PPT
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
PDF
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
PPT
Lecture05
elearning_portal
 
PPTX
constructors and destructors in c++
HalaiHansaika
 
PPT
CPP Language Basics - Reference
Mohammed Sikander
 
DOCX
Oops practical file
Ankit Dixit
 
PDF
2014 computer science_question_paper
vandna123
 
PPTX
cpp promo ppt.pptx
C++ Homework Help
 
Basic c++ programs
harman kaur
 
Pads lab manual final
AhalyaR
 
C++ file
Mukund Trivedi
 
basic programs in C++
Arun Nair
 
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
aassecuritysystem
 
Bijender (1)
Ankush Kumar
 
Final DAA_prints.pdf
Yashpatel821746
 
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
Lecture05
elearning_portal
 
constructors and destructors in c++
HalaiHansaika
 
CPP Language Basics - Reference
Mohammed Sikander
 
Oops practical file
Ankit Dixit
 
2014 computer science_question_paper
vandna123
 
cpp promo ppt.pptx
C++ Homework Help
 

Recently uploaded (20)

PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Immersive experiences: what Pharo users do!
ESUG
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 

C- Programs - Harsh

  • 3. OUTPUT Enter value of a: 45 Enter value of b: 56 Original value of a is:45 Original value of b is:56 After Swapping New value of a is:56 New value of b is:45
  • 4. Output Value of a is: 10 Value of b is: 15 After swapping New Value of a is: 15 New value of b is: 10
  • 5. OUTPUT Enter value of a: 45 Enter value of b: 56 Original value of a is:45 Original value of b is:56 After Swapping New value of a is:56 New value of b is:45
  • 6.  #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;  bnew=anew-bnew;  anew=anew-bnew;  cout<<"new value of a is:"<<anew<<endl;  cout<<"new value of b is:"<<bnew<<endl;  }  void main()  {  int a,b;  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();  } OUTPUT Enter value of a: 25 Enter value of b: 65 Value of a is: 25 Value of b is:65 After swapping Value of a is: 65 Value of b is: 25
  • 7.  #include<iostream.h>  #include<conio.h>  void main()  {  int a[10],i,j,m,loc=0;  clrscr();  cout<<"enter 10 elements of array:";  for(i=0;i<=9;i++)  {  cin>>a[i];  }  m=a[0];  for(j=1;j<=9;j++)  {  if(a[j]>m)  {  m=a[j];  loc=j+1;  }  }  cout<<"max value is:"<<m;  cout<<"its loc is:"<<loc;  getch();  } OUTPUT Enter 10 elements of array: 5 8 2 12 65 36 98 45 25 96 Max value is: 98 Its location is: 7
  • 8.  #include<iostream.h>  #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:";  for(int i=0;i<=9;i++)  {  cin>>a[i];  }  max=a[0];  for(j=1;j<=9;j++)  {  if(a[j]>max)  {  max=a[j];  }  }  return max;  }  };  void main()  {  int max1;  clrscr();  greatest g1;  max1=g1.largest();  cout<<"Greatest of ten values is:"<<max1;  getch();  } OUTPUT Enter 10 elements of array: 5 8 2 12 65 36 98 45 25 96 Max value is: 98
  • 9.  #include<iostream.h>  #include<conio.h>  void main()  {  int min,a[10],I;  clrscr();  cout<<“Enter 10 elements of array.”;  for(i=0;i<=9;i++)  cin>>a[i];  for(j=1;j<=9;j++)  {  If(a[j]<min)  min=a[j];  }  cout<<“smallest of 10 values is:”<<min;  getch();  } OUTPUT Enter 10 elements of array: 5 8 2 12 65 36 98 45 25 96 Smallest of ten values is: 2
  • 10.  #include<iostream.h>  #include<conio.h>  class smallest  {  public:  int a[10],j,min;  int calculate_smallest()  {  cout<<"enter 10 elements of array:";  for(int i=0;i<=9;i++)  {  cin>>a[i];  }  min=a[0]; //0th element is set as minimum values  for(j=1;j<=9;j++)  {  if(a[j]<min)  {  min=a[j];  }  }  return min;  }  };  void main()  {  int min1;  clrscr();  smallest s1;  min1=s1.calculate_smallest();  cout<<“Smallest of ten values is:"<<min1;  getch();  } OUTPUT Enter 10 elements of array: -5 8 2 12 65 36 98 45 25 96 Smallest of ten values is: - 5
  • 11.  #include<iostream.h>  #include<conio.h>  void main()  {  int a , b, c;  clrscr();  cout<<“Enter value of a:”;  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();  } OUTPUT Enter value of a: 56 Enter value of b: 36 56 is greatest.
  • 12.  #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();  cout<<"enter a:";  cin>>a;  cout<<"enter b:";  cin>>b;  comparison c1;  cout<<"Greatest of two values is:"<<c1.greatest(a,b);  getch();  } OUTPUT Enter value of a: 62 Enter value of b: 36 Greatest of two values is:62
  • 13.  #include<iostream.h>  #include<conio.h>  void main()  {  int a , b, c, max;  clrscr();  cout<<"Enter value of a:";  cin>>a;  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();  } OUTPUT Enter value of a: 96 Enter value of b: 125 Enter value of c: 36 36 is greatest

Editor's Notes

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