SlideShare a Scribd company logo
selection_sort..c
#include //header file input output function
#define N 10//default value N=10
void selection_sort(int a[], int n);//function declaration
int *find_largest(int a[], int n);//function declaration
void swap(int *p, int *q);//function declaration
int main(void)
{//main function
int i;
int a[N];//variable declaration
int x,y;
printf("Enter %d numbers to be sorted: ", N);
for (i = 0; i < N; i++)
scanf("%d", &a[i]);//keyboard inputting
selection_sort(a, N);//calling method
printf("In sorted order:");
for (i = 0; i < N; i++)
printf(" %d", a[i]);
printf(" ");
printf("largest element in the array :");
*find_largest(a,N);//calling method
printf(" Enter two variables for swapping :");
scanf("%d",&x);
scanf("%d",&y);
swap(&x,&y);
return 0;
}
void selection_sort(int a[], int n)
{//function definition
int i, largest = 0, temp;
if (n == 1)
return;
for (i = 1; i < n; i++)
if (a[i] > a[largest])
largest = i;//selection sort logic
if (largest < n - 1) {
temp = a[n-1];
a[n-1] = a[largest];
a[largest] = temp;
}
selection_sort(a, n - 1);
}
int *find_largest(int *a, int n)
{//function definition
for(int i=1;i if you want to find smallest element*/
*a=*(a+i);
}
printf("%d",*a);
}
void swap(int *p, int *q)
{//function definition
*p = *p + *q; // x now becomes 15
*q = *p - *q; // y becomes 10
*p = *p - *q; // x becomes 5
printf("After swapping of values :");
printf("%d %d ",*p,*q);
}
output
Enter 10 numbers to be sorted: 562 1 344 6 4 3 2 4 67 8
In sorted order: 1 2 3 4 4 6 8 67 344 562
largest element in the array :562
Enter two variables for swapping :10 20
After swapping of
values :20 10
Solution
selection_sort..c
#include //header file input output function
#define N 10//default value N=10
void selection_sort(int a[], int n);//function declaration
int *find_largest(int a[], int n);//function declaration
void swap(int *p, int *q);//function declaration
int main(void)
{//main function
int i;
int a[N];//variable declaration
int x,y;
printf("Enter %d numbers to be sorted: ", N);
for (i = 0; i < N; i++)
scanf("%d", &a[i]);//keyboard inputting
selection_sort(a, N);//calling method
printf("In sorted order:");
for (i = 0; i < N; i++)
printf(" %d", a[i]);
printf(" ");
printf("largest element in the array :");
*find_largest(a,N);//calling method
printf(" Enter two variables for swapping :");
scanf("%d",&x);
scanf("%d",&y);
swap(&x,&y);
return 0;
}
void selection_sort(int a[], int n)
{//function definition
int i, largest = 0, temp;
if (n == 1)
return;
for (i = 1; i < n; i++)
if (a[i] > a[largest])
largest = i;//selection sort logic
if (largest < n - 1) {
temp = a[n-1];
a[n-1] = a[largest];
a[largest] = temp;
}
selection_sort(a, n - 1);
}
int *find_largest(int *a, int n)
{//function definition
for(int i=1;i if you want to find smallest element*/
*a=*(a+i);
}
printf("%d",*a);
}
void swap(int *p, int *q)
{//function definition
*p = *p + *q; // x now becomes 15
*q = *p - *q; // y becomes 10
*p = *p - *q; // x becomes 5
printf("After swapping of values :");
printf("%d %d ",*p,*q);
}
output
Enter 10 numbers to be sorted: 562 1 344 6 4 3 2 4 67 8
In sorted order: 1 2 3 4 4 6 8 67 344 562
largest element in the array :562
Enter two variables for swapping :10 20
After swapping of
values :20 10

More Related Content

Similar to selection_sort..c#include stdio.hheader file input output func.pdf

Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
arorasales234
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
MAYANKBANSAL1981
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
ARYAN20071
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Lab Question
Lab QuestionLab Question
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
meerobertsonheyde608
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
anandmobile
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
Array Cont
Array ContArray Cont
888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf
apnafreez
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
anandf0099
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
C programming function
C  programming functionC  programming function
C programming function
argusacademy
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 

Similar to selection_sort..c#include stdio.hheader file input output func.pdf (20)

Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Lab Question
Lab QuestionLab Question
Lab Question
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
 
Input output functions
Input output functionsInput output functions
Input output functions
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
Array Cont
Array ContArray Cont
Array Cont
 
888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf888678123317368915236 #include stdio.h #include stdlib.h.pdf
888678123317368915236 #include stdio.h #include stdlib.h.pdf
 
Hi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdfHi,Please fidn the Answer.Sorting,h is Header .pdf
Hi,Please fidn the Answer.Sorting,h is Header .pdf
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
C programming function
C  programming functionC  programming function
C programming function
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 

More from anton291

There are many ways to do the Lewis symbol for yo.pdf
                     There are many ways to do the Lewis symbol for yo.pdf                     There are many ways to do the Lewis symbol for yo.pdf
There are many ways to do the Lewis symbol for yo.pdf
anton291
 
the compound is heptane note the molecular ion.pdf
                     the compound is heptane  note the molecular ion.pdf                     the compound is heptane  note the molecular ion.pdf
the compound is heptane note the molecular ion.pdf
anton291
 
Succinic acid is oxidized C goes from +34 to +1 .pdf
                     Succinic acid is oxidized C goes from +34 to +1 .pdf                     Succinic acid is oxidized C goes from +34 to +1 .pdf
Succinic acid is oxidized C goes from +34 to +1 .pdf
anton291
 
pH = pK +log ([salt][acid]) = pH = -log(1.8 x .pdf
                     pH = pK +log ([salt][acid])  = pH = -log(1.8 x .pdf                     pH = pK +log ([salt][acid])  = pH = -log(1.8 x .pdf
pH = pK +log ([salt][acid]) = pH = -log(1.8 x .pdf
anton291
 
Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
                     Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf                     Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
anton291
 
Moseley used X-ray diffraction to show that each .pdf
                     Moseley used X-ray diffraction to show that each .pdf                     Moseley used X-ray diffraction to show that each .pdf
Moseley used X-ray diffraction to show that each .pdf
anton291
 
Welding is a permanent joining of two similar metals by melting the .pdf
Welding is a permanent joining of two similar metals by melting the .pdfWelding is a permanent joining of two similar metals by melting the .pdf
Welding is a permanent joining of two similar metals by melting the .pdf
anton291
 
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdfUse of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
anton291
 
the solute potential of the plant cell is Greater than the pure wate.pdf
the solute potential of the plant cell is Greater than the pure wate.pdfthe solute potential of the plant cell is Greater than the pure wate.pdf
the solute potential of the plant cell is Greater than the pure wate.pdf
anton291
 
The Human Genome Project (HGP) determines the sequence of nucleotide.pdf
The Human Genome Project (HGP) determines the sequence of nucleotide.pdfThe Human Genome Project (HGP) determines the sequence of nucleotide.pdf
The Human Genome Project (HGP) determines the sequence of nucleotide.pdf
anton291
 
solutionlist intersect(list L1, list L2){list result;positi.pdf
solutionlist intersect(list L1, list L2){list result;positi.pdfsolutionlist intersect(list L1, list L2){list result;positi.pdf
solutionlist intersect(list L1, list L2){list result;positi.pdf
anton291
 
Sorry for not seeing const temp, The answers are-The reaction abso.pdf
Sorry for not seeing const temp, The answers are-The reaction abso.pdfSorry for not seeing const temp, The answers are-The reaction abso.pdf
Sorry for not seeing const temp, The answers are-The reaction abso.pdf
anton291
 
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdfSO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
anton291
 
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdfQ2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
anton291
 
Nucleus is the dense central part of an atom. .pdf
                     Nucleus  is the dense central part of an atom.   .pdf                     Nucleus  is the dense central part of an atom.   .pdf
Nucleus is the dense central part of an atom. .pdf
anton291
 
Its demorgans theorem. Draw truth table to verify.pdf
                     Its demorgans theorem. Draw truth table to verify.pdf                     Its demorgans theorem. Draw truth table to verify.pdf
Its demorgans theorem. Draw truth table to verify.pdf
anton291
 
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdfIonic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
anton291
 
I will help .SolutionI will help ..pdf
I will help .SolutionI will help ..pdfI will help .SolutionI will help ..pdf
I will help .SolutionI will help ..pdf
anton291
 
HDL!SolutionHDL!.pdf
HDL!SolutionHDL!.pdfHDL!SolutionHDL!.pdf
HDL!SolutionHDL!.pdf
anton291
 
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdf
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdfDicer it is also referred as endoribonuclease Dicer. It has activit.pdf
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdf
anton291
 

More from anton291 (20)

There are many ways to do the Lewis symbol for yo.pdf
                     There are many ways to do the Lewis symbol for yo.pdf                     There are many ways to do the Lewis symbol for yo.pdf
There are many ways to do the Lewis symbol for yo.pdf
 
the compound is heptane note the molecular ion.pdf
                     the compound is heptane  note the molecular ion.pdf                     the compound is heptane  note the molecular ion.pdf
the compound is heptane note the molecular ion.pdf
 
Succinic acid is oxidized C goes from +34 to +1 .pdf
                     Succinic acid is oxidized C goes from +34 to +1 .pdf                     Succinic acid is oxidized C goes from +34 to +1 .pdf
Succinic acid is oxidized C goes from +34 to +1 .pdf
 
pH = pK +log ([salt][acid]) = pH = -log(1.8 x .pdf
                     pH = pK +log ([salt][acid])  = pH = -log(1.8 x .pdf                     pH = pK +log ([salt][acid])  = pH = -log(1.8 x .pdf
pH = pK +log ([salt][acid]) = pH = -log(1.8 x .pdf
 
Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
                     Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf                     Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
Step1 25 ml of1M HCl w ill neutralise 25 ml 1 M N.pdf
 
Moseley used X-ray diffraction to show that each .pdf
                     Moseley used X-ray diffraction to show that each .pdf                     Moseley used X-ray diffraction to show that each .pdf
Moseley used X-ray diffraction to show that each .pdf
 
Welding is a permanent joining of two similar metals by melting the .pdf
Welding is a permanent joining of two similar metals by melting the .pdfWelding is a permanent joining of two similar metals by melting the .pdf
Welding is a permanent joining of two similar metals by melting the .pdf
 
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdfUse of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
Use of oxygen for ATP synthesis is called as Aerobic respiration. Th.pdf
 
the solute potential of the plant cell is Greater than the pure wate.pdf
the solute potential of the plant cell is Greater than the pure wate.pdfthe solute potential of the plant cell is Greater than the pure wate.pdf
the solute potential of the plant cell is Greater than the pure wate.pdf
 
The Human Genome Project (HGP) determines the sequence of nucleotide.pdf
The Human Genome Project (HGP) determines the sequence of nucleotide.pdfThe Human Genome Project (HGP) determines the sequence of nucleotide.pdf
The Human Genome Project (HGP) determines the sequence of nucleotide.pdf
 
solutionlist intersect(list L1, list L2){list result;positi.pdf
solutionlist intersect(list L1, list L2){list result;positi.pdfsolutionlist intersect(list L1, list L2){list result;positi.pdf
solutionlist intersect(list L1, list L2){list result;positi.pdf
 
Sorry for not seeing const temp, The answers are-The reaction abso.pdf
Sorry for not seeing const temp, The answers are-The reaction abso.pdfSorry for not seeing const temp, The answers are-The reaction abso.pdf
Sorry for not seeing const temp, The answers are-The reaction abso.pdf
 
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdfSO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
SO2 = 18IF4+ = 34I3- = 22The easiest way to think about this i.pdf
 
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdfQ2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
Q2.AnswerThe Toll -like receptor encodes a protein which plays .pdf
 
Nucleus is the dense central part of an atom. .pdf
                     Nucleus  is the dense central part of an atom.   .pdf                     Nucleus  is the dense central part of an atom.   .pdf
Nucleus is the dense central part of an atom. .pdf
 
Its demorgans theorem. Draw truth table to verify.pdf
                     Its demorgans theorem. Draw truth table to verify.pdf                     Its demorgans theorem. Draw truth table to verify.pdf
Its demorgans theorem. Draw truth table to verify.pdf
 
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdfIonic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
Ionic Bonds (between ionic molecules) - Medium strong bond - In an.pdf
 
I will help .SolutionI will help ..pdf
I will help .SolutionI will help ..pdfI will help .SolutionI will help ..pdf
I will help .SolutionI will help ..pdf
 
HDL!SolutionHDL!.pdf
HDL!SolutionHDL!.pdfHDL!SolutionHDL!.pdf
HDL!SolutionHDL!.pdf
 
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdf
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdfDicer it is also referred as endoribonuclease Dicer. It has activit.pdf
Dicer it is also referred as endoribonuclease Dicer. It has activit.pdf
 

Recently uploaded

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

selection_sort..c#include stdio.hheader file input output func.pdf

  • 1. selection_sort..c #include //header file input output function #define N 10//default value N=10 void selection_sort(int a[], int n);//function declaration int *find_largest(int a[], int n);//function declaration void swap(int *p, int *q);//function declaration int main(void) {//main function int i; int a[N];//variable declaration int x,y; printf("Enter %d numbers to be sorted: ", N); for (i = 0; i < N; i++) scanf("%d", &a[i]);//keyboard inputting selection_sort(a, N);//calling method printf("In sorted order:"); for (i = 0; i < N; i++) printf(" %d", a[i]); printf(" "); printf("largest element in the array :"); *find_largest(a,N);//calling method printf(" Enter two variables for swapping :"); scanf("%d",&x); scanf("%d",&y); swap(&x,&y); return 0; } void selection_sort(int a[], int n) {//function definition int i, largest = 0, temp; if (n == 1) return; for (i = 1; i < n; i++) if (a[i] > a[largest]) largest = i;//selection sort logic
  • 2. if (largest < n - 1) { temp = a[n-1]; a[n-1] = a[largest]; a[largest] = temp; } selection_sort(a, n - 1); } int *find_largest(int *a, int n) {//function definition for(int i=1;i if you want to find smallest element*/ *a=*(a+i); } printf("%d",*a); } void swap(int *p, int *q) {//function definition *p = *p + *q; // x now becomes 15 *q = *p - *q; // y becomes 10 *p = *p - *q; // x becomes 5 printf("After swapping of values :"); printf("%d %d ",*p,*q); } output Enter 10 numbers to be sorted: 562 1 344 6 4 3 2 4 67 8 In sorted order: 1 2 3 4 4 6 8 67 344 562 largest element in the array :562 Enter two variables for swapping :10 20 After swapping of values :20 10 Solution selection_sort..c
  • 3. #include //header file input output function #define N 10//default value N=10 void selection_sort(int a[], int n);//function declaration int *find_largest(int a[], int n);//function declaration void swap(int *p, int *q);//function declaration int main(void) {//main function int i; int a[N];//variable declaration int x,y; printf("Enter %d numbers to be sorted: ", N); for (i = 0; i < N; i++) scanf("%d", &a[i]);//keyboard inputting selection_sort(a, N);//calling method printf("In sorted order:"); for (i = 0; i < N; i++) printf(" %d", a[i]); printf(" "); printf("largest element in the array :"); *find_largest(a,N);//calling method printf(" Enter two variables for swapping :"); scanf("%d",&x); scanf("%d",&y); swap(&x,&y); return 0; } void selection_sort(int a[], int n) {//function definition int i, largest = 0, temp; if (n == 1) return; for (i = 1; i < n; i++) if (a[i] > a[largest]) largest = i;//selection sort logic if (largest < n - 1) { temp = a[n-1];
  • 4. a[n-1] = a[largest]; a[largest] = temp; } selection_sort(a, n - 1); } int *find_largest(int *a, int n) {//function definition for(int i=1;i if you want to find smallest element*/ *a=*(a+i); } printf("%d",*a); } void swap(int *p, int *q) {//function definition *p = *p + *q; // x now becomes 15 *q = *p - *q; // y becomes 10 *p = *p - *q; // x becomes 5 printf("After swapping of values :"); printf("%d %d ",*p,*q); } output Enter 10 numbers to be sorted: 562 1 344 6 4 3 2 4 67 8 In sorted order: 1 2 3 4 4 6 8 67 344 562 largest element in the array :562 Enter two variables for swapping :10 20 After swapping of values :20 10