Static Table...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • haste

    Static Table...

    I have to write code in C++ wchich fill Table in this style:
    | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
    | 192 | 96 | 48 | 24 | 12 | 6 | 3 |
    | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
    | 320 | 160 | 80 | 40 | 20 | 10 | 5 |
    Table [4][7] - Hww to make it?


  • Jurko Gospodnetiæ

    #2
    Re: Static Table...

    Hi haste.
    [color=blue]
    >I have to write code in C++ wchich fill Table in this style:
    > | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
    > | 192 | 96 | 48 | 24 | 12 | 6 | 3 |
    > | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
    > | 320 | 160 | 80 | 40 | 20 | 10 | 5 |
    > Table [4][7] - Hww to make it?[/color]

    int table[4][7] =
    {
    { 2, 4, 8, 16, 32, 64, 128 },
    { 192, 96, 48, 24, 12, 6, 3 },
    { 4, 8, 16, 32, 128, 256 },
    { 320, 160, 80, 40, 20, 10, 5 }
    };

    Didn't test for syntax errors >:-) but should work...

    Hope it helps.

    Best regards,
    Jurko Gospodnetiæ


    Comment

    • haste

      #3
      Re: Static Table...

      > int table[4][7] =[color=blue]
      > {
      > { 2, 4, 8, 16, 32, 64, 128 },
      > { 192, 96, 48, 24, 12, 6, 3 },
      > { 4, 8, 16, 32, 128, 256 },
      > { 320, 160, 80, 40, 20, 10, 5 }
      > };
      >
      > Didn't test for syntax errors >:-) but should work...[/color]

      But It must be automatical NO manual.... Loop or something....


      Comment

      • Ian Collins

        #4
        Re: Static Table...

        haste wrote:[color=blue]
        > I have to write code in C++ wchich fill Table in this style:
        > | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
        > | 192 | 96 | 48 | 24 | 12 | 6 | 3 |
        > | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
        > | 320 | 160 | 80 | 40 | 20 | 10 | 5 |
        > Table [4][7] - Hww to make it?
        >
        >[/color]
        What have you tried?

        --
        Ian Collins.

        Comment

        • haste

          #5
          Re: Static Table...

          [color=blue]
          > What have you tried?
          >[/color]
          I'm in work...I can't try...This is for my friend...


          Comment

          • Marcin Gabryszewski

            #6
            Re: Static Table...

            haste wrote:
            [color=blue]
            > I have to write code in C++ wchich fill Table in this style:
            > | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
            > | 192 | 96 | 48 | 24 | 12 | 6 | 3 |
            > | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
            > | 320 | 160 | 80 | 40 | 20 | 10 | 5 |
            > Table [4][7] - Hww to make it?
            >
            >[/color]
            here you are :)

            #define rows 4
            #define cols 7
            std::vector< std::vector<int > > t2;
            for( size_t i = 1; i <= rows; i++ ){
            std::vector<int > col;
            int iVal = i+1;
            col.push_back( iVal );
            for( size_t n = 1; n < cols; n++ ){
            iVal *= 2;
            if( i&1 )
            col.push_back( iVal );
            else
            col.insert( col.begin(), iVal );
            }
            t2.push_back(co l);
            }
            //print table
            for( std::vector< std::vector<int > >::iterator it= t2.begin();
            it != t2.end(); ++it ){
            std::copy( it->begin(), it->end(),
            std::ostream_it erator<int>(std ::cout, " | ") );
            std::cout << std::endl;
            }

            --
            Marcin Gabryszewski
            G DATA Software


            address:[FirstName][SurnameFirstLet ter]@gdata.pl

            Comment

            • Ben Pope

              #7
              Re: Static Table...

              haste wrote:[color=blue][color=green]
              >> int table[4][7] =
              >> {
              >> { 2, 4, 8, 16, 32, 64, 128 },
              >> { 192, 96, 48, 24, 12, 6, 3 },
              >> { 4, 8, 16, 32, 128, 256 },
              >> { 320, 160, 80, 40, 20, 10, 5 }
              >> };
              >>
              >> Didn't test for syntax errors >:-) but should work...[/color]
              >
              > But It must be automatical NO manual.... Loop or something....[/color]

              Yes a loop and an algorithm.

              Ben Pope
              --
              I'm not just a number. To many, I'm known as a string...

              Comment

              • Stephan Brönnimann

                #8
                Re: Static Table...

                haste wrote:[color=blue][color=green]
                > > int table[4][7] =
                > > {
                > > { 2, 4, 8, 16, 32, 64, 128 },
                > > { 192, 96, 48, 24, 12, 6, 3 },
                > > { 4, 8, 16, 32, 128, 256 },
                > > { 320, 160, 80, 40, 20, 10, 5 }
                > > };
                > >
                > > Didn't test for syntax errors >:-) but should work...[/color]
                >
                > But It must be automatical NO manual.... Loop or something....[/color]

                What is allowed then:-?

                Stephan

                Comment

                • osmium

                  #9
                  Re: Static Table...

                  "haste" writes:
                  [color=blue][color=green]
                  >> int table[4][7] =
                  >> {
                  >> { 2, 4, 8, 16, 32, 64, 128 },
                  >> { 192, 96, 48, 24, 12, 6, 3 },
                  >> { 4, 8, 16, 32, 128, 256 },
                  >> { 320, 160, 80, 40, 20, 10, 5 }
                  >> };
                  >>
                  >> Didn't test for syntax errors >:-) but should work...[/color]
                  >
                  > But It must be automatical NO manual.... Loop or something....[/color]

                  Look for patterns. Since there is more than one line there may be more than
                  one pattern. You have to do the math first, *then* the program. Does the
                  phrase "arithmetic progression" ring a bell?


                  Comment

                  • red floyd

                    #10
                    Re: Static Table...

                    haste wrote:[color=blue][color=green]
                    >> int table[4][7] =
                    >> {
                    >> { 2, 4, 8, 16, 32, 64, 128 },
                    >> { 192, 96, 48, 24, 12, 6, 3 },
                    >> { 4, 8, 16, 32, 128, 256 },
                    >> { 320, 160, 80, 40, 20, 10, 5 }
                    >> };
                    >>
                    >> Didn't test for syntax errors >:-) but should work...[/color]
                    >
                    > But It must be automatical NO manual.... Loop or something....
                    >[/color]

                    Post your instructors email, and we'll send him the answer.

                    Comment

                    • Jim Langston

                      #11
                      Re: Static Table...


                      "haste" <haste@nospam.i rc.pl> wrote in message
                      news:drsdv4$ktb $1@inews.gazeta .pl...[color=blue]
                      >I have to write code in C++ wchich fill Table in this style:
                      > | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
                      > | 192 | 96 | 48 | 24 | 12 | 6 | 3 |
                      > | 4 | 8 | 16 | 32 | 64 | 128 | 256 |
                      > | 320 | 160 | 80 | 40 | 20 | 10 | 5 |
                      > Table [4][7] - Hww to make it?
                      >
                      >[/color]

                      Hint. 2, 4, 8, 16...
                      2*2 = 4. 2*2*2 = 8, 2*2*2*2 = 16...


                      Comment

                      Working...