W.A.P. C++

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

Snehil Khanor's Binary Log

Write a program to sort elements of array using Insert 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. main() 
  3. int a[100],n,k,i,j,temp; 
  4. printf("How many elements: \n"); 
  5. scanf("%d",&n); 
  6. printf("Enter the element of array: \n"); 
  7. for(i=0;i<=n-1;i++) 
  8. scanf("%d",&a[i]); 
  9. for(k=1;k<=n-1;k++) 
  10. temp=a[k]; 
  11. j=k-1; 
  12. //Coding by: Snehil Khanor 
  13. //http://WapCPP.blogspot.com 
  14. while((temp<a[j])&&(j>=0)) 
  15. a[j+1]=a[j]; 
  16. j=j-1; 
  17. a[j+1]=temp; 
  18. printf("Elements of array after sorting: \n"); 
  19. for(i=0;i<=n-1;i++) 
  20. printf("%d\n",a[i]); 
  21. 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



eXTReMe Tracker