Powered by Blogger.

Tuesday, February 5, 2013

sorting

/*Q.N 3. Write a C++ code to sort the given 10 numbers in assending order .*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>

class sort
{
      int val[10];
      public:
             void getval(void);
             void sorts(void);
             void disp(void);
             };
            
      void sort::getval()
      {
           int i;
           cout<<"\nEnter 5 integer Data : \n";
           for(i=0;i<5;i++)
           {
                            cout<<"\nEnter Value "<<i+1<<" :";
                            cin>>val[i];
                            }
                            }
                           
      void sort::sorts()
      {
           int i,j,temp;
          
           for(j=0;j<5;j++)
           {
                           for(i=0;i<4;i++)
                           {
                                           if(val[i]>val[i+1])
                                           {
                                                              temp=val[i];
                                                              val[i]=val[i+1];
                                                              val[i+1]=temp;
                                                              }
                                                              }
                                                              }
                                                              }
                                                             
      void sort::disp()
      {
           int i;
           cout<<"\nThe Sorted Array : \n";
           for(i=0;i<5;i++)
           {
                            cout<<"\nValue "<<i+1<<":"<<val[i];
                            }
                            }
                           
      int main()
      {
          sort S;
          S.getval();
          S.sorts();
          S.disp();
          getch();
          return 0;
          }
                           
          

0 comments:

Post a Comment