SlideShare une entreprise Scribd logo
1  sur  6
1.wap to print to accept integer from user and print
only those elements which are greater than
average
// A C++ program to print elements which are
// greater than avg of array
#include <iostream.h>
using namespace std;
// Print array elements greater than average
void printAboveAvg(int arr[], int n)
{
// Find average
double avg = 0;
for (int i = 0; i < n; i++)
avg += arr[i];
avg = avg / n;
// Print elements greater than average
for (int i = 0; i < n; i++)
if (arr[i] > avg)
cout << arr[i] << " ";
}
// Driver program
int main()
{
int arr[] = { 5, 4, 6, 9, 10 };
int a = sizeof(arr) / sizeof(arr[0]);
printAboveAvg(arr, a);
return 0;
}
Output:
9 10
2.
For a quadratic equation ax2
+bx+c = 0 (where a, b
and c are coefficients), it's roots is given by
following the formula.
The term b2
-4ac is known as the discriminant of a
quadratic equation. The discriminant tells the nature
of the roots.
1.#include <iostream>
2.#include <cmath>
3.using namespace std;
4.
5.int main() {
6.
7. float a, b, c, x1, x2, discriminant, realPart,
imaginaryPart;
8. cout << "Enter coefficients a, b and c: ";
9. cin >> a >> b >> c;
10. discriminant = b*b - 4*a*c;
11.
12. if (discriminant > 0) {
13. x1 = (-b + sqrt(discriminant)) / (2*a);
14. x2 = (-b - sqrt(discriminant)) / (2*a);
15. cout << "Roots are real and different." <<
endl;
16. cout << "x1 = " << x1 << endl;
17. cout << "x2 = " << x2 << endl;
18. }
19.
20. else if (discriminant == 0) {
21. cout << "Roots are real and same." << endl;
22. x1 = (-b + sqrt(discriminant)) / (2*a);
23. cout << "x1 = x2 =" << x1 << endl;
24. }
25.
26. else {
27. realPart = -b/(2*a);
28. imaginaryPart =sqrt(-discriminant)/(2*a);
29. cout << "Roots are complex and different."
<< endl;
30. cout << "x1 = " << realPart << "+" <<
imaginaryPart << "i" << endl;
31. cout << "x2 = " << realPart << "-" <<
imaginaryPart << "i" << endl;
32. }
33.
34. return 0;
35. }
Output
Enter coefficients a, b and c: 4
5
1
Roots are real and different.
x1 = -0.25
x2 = -1
Cpp

Contenu connexe

Tendances (20)

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
20151224-games
20151224-games20151224-games
20151224-games
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Include
IncludeInclude
Include
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
Oops in c++
Oops in c++Oops in c++
Oops in c++
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
Include
IncludeInclude
Include
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Oopsprc1c
Oopsprc1cOopsprc1c
Oopsprc1c
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
Program(Output)
Program(Output)Program(Output)
Program(Output)
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
 
Class array
Class arrayClass array
Class array
 
Modificacion del programa
Modificacion del programaModificacion del programa
Modificacion del programa
 
Ooprc3c
Ooprc3cOoprc3c
Ooprc3c
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
Assignement c++
Assignement c++Assignement c++
Assignement c++
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cpp
 

Similaire à Cpp (20)

CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Cpl
CplCpl
Cpl
 
Oop1
Oop1Oop1
Oop1
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
C++ Programs
C++ ProgramsC++ Programs
C++ Programs
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Control flow Graph
Control flow GraphControl flow Graph
Control flow Graph
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 

Plus de Ankit Dubey

Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}Ankit Dubey
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-schedulingAnkit Dubey
 
Ch2 system structure
Ch2 system structureCh2 system structure
Ch2 system structureAnkit Dubey
 
Ch1 introduction-to-os
Ch1 introduction-to-osCh1 introduction-to-os
Ch1 introduction-to-osAnkit Dubey
 
Mongodb mock test_ii
Mongodb mock test_iiMongodb mock test_ii
Mongodb mock test_iiAnkit Dubey
 
Android mock test_iii
Android mock test_iiiAndroid mock test_iii
Android mock test_iiiAnkit Dubey
 
Android mock test_ii
Android mock test_iiAndroid mock test_ii
Android mock test_iiAnkit Dubey
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06Ankit Dubey
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05Ankit Dubey
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04Ankit Dubey
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03Ankit Dubey
 

Plus de Ankit Dubey (20)

Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}Unit 1 android and it's tools quiz {mad cwipedia}
Unit 1 android and it's tools quiz {mad cwipedia}
 
Scheduling
Scheduling Scheduling
Scheduling
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Ch5 cpu-scheduling
Ch5 cpu-schedulingCh5 cpu-scheduling
Ch5 cpu-scheduling
 
Ch4 threads
Ch4 threadsCh4 threads
Ch4 threads
 
Ch3 processes
Ch3 processesCh3 processes
Ch3 processes
 
Ch2 system structure
Ch2 system structureCh2 system structure
Ch2 system structure
 
Ch1 introduction-to-os
Ch1 introduction-to-osCh1 introduction-to-os
Ch1 introduction-to-os
 
Android i
Android iAndroid i
Android i
 
Mongodb mock test_ii
Mongodb mock test_iiMongodb mock test_ii
Mongodb mock test_ii
 
Android mock test_iii
Android mock test_iiiAndroid mock test_iii
Android mock test_iii
 
Android mock test_ii
Android mock test_iiAndroid mock test_ii
Android mock test_ii
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
 
Ajp notes-chapter-04
Ajp notes-chapter-04Ajp notes-chapter-04
Ajp notes-chapter-04
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 

Dernier

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Dernier (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Cpp

  • 1. 1.wap to print to accept integer from user and print only those elements which are greater than average // A C++ program to print elements which are // greater than avg of array #include <iostream.h> using namespace std; // Print array elements greater than average void printAboveAvg(int arr[], int n) { // Find average double avg = 0; for (int i = 0; i < n; i++) avg += arr[i]; avg = avg / n; // Print elements greater than average for (int i = 0; i < n; i++) if (arr[i] > avg) cout << arr[i] << " ";
  • 2. } // Driver program int main() { int arr[] = { 5, 4, 6, 9, 10 }; int a = sizeof(arr) / sizeof(arr[0]); printAboveAvg(arr, a); return 0; } Output: 9 10 2. For a quadratic equation ax2 +bx+c = 0 (where a, b and c are coefficients), it's roots is given by following the formula.
  • 3. The term b2 -4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots. 1.#include <iostream> 2.#include <cmath> 3.using namespace std;
  • 4. 4. 5.int main() { 6. 7. float a, b, c, x1, x2, discriminant, realPart, imaginaryPart; 8. cout << "Enter coefficients a, b and c: "; 9. cin >> a >> b >> c; 10. discriminant = b*b - 4*a*c; 11. 12. if (discriminant > 0) { 13. x1 = (-b + sqrt(discriminant)) / (2*a); 14. x2 = (-b - sqrt(discriminant)) / (2*a); 15. cout << "Roots are real and different." << endl; 16. cout << "x1 = " << x1 << endl; 17. cout << "x2 = " << x2 << endl; 18. } 19. 20. else if (discriminant == 0) { 21. cout << "Roots are real and same." << endl; 22. x1 = (-b + sqrt(discriminant)) / (2*a); 23. cout << "x1 = x2 =" << x1 << endl; 24. } 25. 26. else {
  • 5. 27. realPart = -b/(2*a); 28. imaginaryPart =sqrt(-discriminant)/(2*a); 29. cout << "Roots are complex and different." << endl; 30. cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl; 31. cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl; 32. } 33. 34. return 0; 35. } Output Enter coefficients a, b and c: 4 5 1 Roots are real and different. x1 = -0.25 x2 = -1