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 :)
- #include<stdio.h>
- main()
- {
- int a[100],n,k,i,j,temp;
- printf("How many elements: \n");
- scanf("%d",&n);
- printf("Enter the element of array: \n");
- for(i=0;i<=n-1;i++)
- scanf("%d",&a[i]);
- for(k=1;k<=n-1;k++)
- {
- temp=a[k];
- j=k-1;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- while((temp<a[j])&&(j>=0))
- {
- a[j+1]=a[j];
- j=j-1;
- }
- a[j+1]=temp;
- }
- printf("Elements of array after sorting: \n");
- for(i=0;i<=n-1;i++)
- printf("%d\n",a[i]);
- getch();
- }
0 comments:
Post a Comment