Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. need to give the number of middle

need to give the number of middle

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    youbo
    wrote on last edited by
    #1

    when somebody input some number,you need give out the number of middle.my code is follow:#include using namespace std; void swap(int &a,int &b); void main() { int n=0,k,m,j; int*p=new int[n]; cin>>n; k=n; j=n; m=n; for(;n>0;n--) { cin>>p[n-1]; } int x=1; while(x) { x=0; for(;k>0;k--) { if(p[k-1]

    D C 2 Replies Last reply
    0
    • Y youbo

      when somebody input some number,you need give out the number of middle.my code is follow:#include using namespace std; void swap(int &a,int &b); void main() { int n=0,k,m,j; int*p=new int[n]; cin>>n; k=n; j=n; m=n; for(;n>0;n--) { cin>>p[n-1]; } int x=1; while(x) { x=0; for(;k>0;k--) { if(p[k-1]

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      youbo wrote:

      the number of middle.

      AKA the median.

      youbo wrote:

      my code is follow

      Congratulations. :rolleyes:


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      Y 1 Reply Last reply
      0
      • D David Crow

        youbo wrote:

        the number of middle.

        AKA the median.

        youbo wrote:

        my code is follow

        Congratulations. :rolleyes:


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        Y Offline
        Y Offline
        youbo
        wrote on last edited by
        #3

        - -!!

        D 1 Reply Last reply
        0
        • Y youbo

          when somebody input some number,you need give out the number of middle.my code is follow:#include using namespace std; void swap(int &a,int &b); void main() { int n=0,k,m,j; int*p=new int[n]; cin>>n; k=n; j=n; m=n; for(;n>0;n--) { cin>>p[n-1]; } int x=1; while(x) { x=0; for(;k>0;k--) { if(p[k-1]

          C Offline
          C Offline
          carrivick
          wrote on last edited by
          #4

          Here you go void swap(int &a,int &b); void main() { int array_size=0,k,m,j; cin>>array_size; if(array_size < 1) return; int*p=new int[array_size]; for(int i=0;i>p[i]; } // Lets do a bubble sort bool changed = true; int bubble_end = array_size - 1; while(changed) { changed = false; for(int i=0;i p[i+1]) { swap(p[i],p[i+1]); changed = true; } } } if(array_size > 1) { if(array_size%2==1) cout< -- modified at 8:50 Saturday 15th September, 2007

          Y 1 Reply Last reply
          0
          • C carrivick

            Here you go void swap(int &a,int &b); void main() { int array_size=0,k,m,j; cin>>array_size; if(array_size < 1) return; int*p=new int[array_size]; for(int i=0;i>p[i]; } // Lets do a bubble sort bool changed = true; int bubble_end = array_size - 1; while(changed) { changed = false; for(int i=0;i p[i+1]) { swap(p[i],p[i+1]); changed = true; } } } if(array_size > 1) { if(array_size%2==1) cout< -- modified at 8:50 Saturday 15th September, 2007

            Y Offline
            Y Offline
            youbo
            wrote on last edited by
            #5

            thank you first,but i couldn't find out the differences from your code to mine.i have run it ,it appeared the same wrong that is not i need. my code in the same with yours is looked right....

            C 1 Reply Last reply
            0
            • Y youbo

              - -!!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Is dash space dash exclamation exclamation an abbreviation for something?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              1 Reply Last reply
              0
              • Y youbo

                thank you first,but i couldn't find out the differences from your code to mine.i have run it ,it appeared the same wrong that is not i need. my code in the same with yours is looked right....

                C Offline
                C Offline
                carrivick
                wrote on last edited by
                #7

                Look more closely void main() { int n=0,k,m,j; **//n is Zero so you declare an array of zero size !** int*p=new int[n]; **// To late you update the value of n** cin>>n; k=n; j=n; m=n; for(;n>0;n--) { cin>>p[n-1]; } int x=1; while(x) { x=0; for(;k>0;k--) { **// This syntax is just wrong try to understand rather than just getting it to compile** if(p[k-1] { swap(p[k-1],p[k]); x=1; } } } **// What if only one element is enter opps were off the end of the array** if(m%2==1){cout<get this,it is also wrong.please have

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups