W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Write a program to sort elements of array using Selection Sorting


Size of array is taken from user.. Elements are entered by user in any order... Sorting is performed..

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<stdio.h> 
  2. #include<conio.h> 
  3. void main() 
  4. int a[100],n,i,j,temp,loc,min; 
  5. clrscr(); 
  6. printf("\How many elements:\n"); 
  7. scanf("%d",&n); 
  8. printf("Enter the element of array\n"); 
  9. for(i=0;i<=n-1;i++) 
  10. scanf("%d",&a[i]); 
  11. min=a[0]; 
  12. //Coding by: Snehil Khanor  
  13. //http://WapCPP.blogspot.com  
  14. for(i=0;i<=n-1;i++) 
  15. min=a[i]; 
  16. loc=i; 
  17. for(j=i+1;j<=n-1;j++) 
  18. if(a[j]<min) 
  19. min=a[j]; 
  20. loc=j; 
  21. if(loc!=1) 
  22. temp=a[i]; 
  23. a[i]=a[loc]; 
  24. a[loc]=temp; 
  25.  
  26. printf("The number after selection sorting are:\n"); 
  27. for(i=0;i<=n-1;i++) 
  28. printf("%d\n",a[i]); 
  29. getch(); 

0 comments:

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Recent Posts



eXTReMe Tracker