Saturday, August 21, 2010

Article | C Program Selection Sort

C Program For Selection Sort of different Numbers using array. Without using any string functions


  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {

  5. int k;

  6. do

  7. {

  8. int a[100],n,temp,i,j,s,num,l,u,m,o,flag=0;

  9. clrscr();

  10. printf(" Enter No Of Elements : ");

  11. scanf("%d",&n);

  12. for(i=0;i<n;i++)

  13. {

  14. printf("\n Enter The %d Element : ",(i+1));

  15. scanf("%d",&a[i]);

  16. }

  17. printf("\n The Entered Array Is \n");

  18. for(i=0;i<n;i++)

  19. printf("%d , ",a[i]);

  20. for(i=0;i<n;i++)

  21. {

  22. for(j=i+1;j<n;j++)

  23. {

  24. if(a[i]>a[j])

  25. {

  26. temp=a[i];

  27. a[i]=a[j];

  28. a[j]=temp;

  29. }

  30. }

  31. }

  32. printf("\n Enter the element to be searched : ");

  33. scanf("%d",&num);

  34. l=0;

  35. o=n;

  36. while(l<=n)

  37. {

  38. m=(l+o);

  39. if(a[m]==num)

  40. {

  41. printf(" The Number is found at the Position %d ",m+1);

  42. flag=1;

  43. break;

  44. }

  45. else if(num<a[m])

  46. o=m-1;

  47. else

  48. l=m+1;

  49. }

  50. if(flag==0)

  51. printf("\n The Number is Absent in the entered Array");

  52. getch();

  53. printf("\n\n\t*** Do U Want To Continue Press 1 ***");

  54. printf("\n\t Enter YOur Choice, For exit Simply click Any Other Key ");

  55. scanf("%d",&k);

  56. }while(k==1);


  57. }

Loading...

Comments :

0 comments to “ C Program Selection Sort ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers