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. Doubt

Doubt

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
13 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.
  • U User 11745560

    Hi sir need clear a explanation for this problem (n = 3)??wap for this 1###1 33#33 55555 33#33 1###1 at the place of (#) should come spaces

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Member 11779027 wrote:

    need clear a explanation for this problem

    That is a fairly basic logic/counting problem that you should be able to figure out by writing the numbers on paper, and deciding how to calculate the number of digits vs the number of spaces for each value.

    U 1 Reply Last reply
    0
    • U User 11745560

      Hi sir need clear a explanation for this problem (n = 3)??wap for this 1###1 33#33 55555 33#33 1###1 at the place of (#) should come spaces

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #3

      You could make some reasoning about row number and to-be-produced pattern:

      0 1###1
      1 33#33
      2 55555
      3 33#33
      4 1###1

      The first point could be observig that

      pattern(0) == pattern(4)
      pattern(1) == pattern(3)
      pattern(2) == pattern(2)

      all hold true. In other words

      pattern(k) == pattern(4-k)

      hold true for

      k = 0, 1 , 2;

      Go on and post specific questions when you are not able to continue.

      In testa che avete, signor di Ceprano?

      U 2 Replies Last reply
      0
      • CPalliniC CPallini

        You could make some reasoning about row number and to-be-produced pattern:

        0 1###1
        1 33#33
        2 55555
        3 33#33
        4 1###1

        The first point could be observig that

        pattern(0) == pattern(4)
        pattern(1) == pattern(3)
        pattern(2) == pattern(2)

        all hold true. In other words

        pattern(k) == pattern(4-k)

        hold true for

        k = 0, 1 , 2;

        Go on and post specific questions when you are not able to continue.

        U Offline
        U Offline
        User 11745560
        wrote on last edited by
        #4

        #include #include int main() { int num=3; for(int r1=1;r1<=num;r1++) { for(int c1=1;c1<=r1;c1++) { printf("*"); } for(int s1=r1;s1=1;r2--) { for(int c2=1;c2<=r2;c2++) { printf("*"); } for(int s1=r2;s1

        1 Reply Last reply
        0
        • CPalliniC CPallini

          You could make some reasoning about row number and to-be-produced pattern:

          0 1###1
          1 33#33
          2 55555
          3 33#33
          4 1###1

          The first point could be observig that

          pattern(0) == pattern(4)
          pattern(1) == pattern(3)
          pattern(2) == pattern(2)

          all hold true. In other words

          pattern(k) == pattern(4-k)

          hold true for

          k = 0, 1 , 2;

          Go on and post specific questions when you are not able to continue.

          U Offline
          U Offline
          User 11745560
          wrote on last edited by
          #5

          #include #include int main() { int num=3; for(int r1=1;r1<=num;r1++) { for(int c1=1;c1<=r1;c1++) { printf("*"); } for(int s1=r1;s1=1;r2--) { for(int c2=1;c2<=r2;c2++) { printf("*"); } for(int s1=r2;s1

          1 Reply Last reply
          0
          • L Lost User

            Member 11779027 wrote:

            need clear a explanation for this problem

            That is a fairly basic logic/counting problem that you should be able to figure out by writing the numbers on paper, and deciding how to calculate the number of digits vs the number of spaces for each value.

            U Offline
            U Offline
            User 11745560
            wrote on last edited by
            #6

            Sir Thanks for your advice Finally done!!! but check it once and report me back if any problem is there in coding #include #include int main() { int num=3; for(int r1=1;r1<=num;r1++) { for(int c1=1;c1<=r1;c1++) { printf("*"); } for(int s1=r1;s1=1;r2--) { for(int c2=1;c2<=r2;c2++) { printf("*"); } for(int s1=r2;s1

            L 1 Reply Last reply
            0
            • U User 11745560

              Sir Thanks for your advice Finally done!!! but check it once and report me back if any problem is there in coding #include #include int main() { int num=3; for(int r1=1;r1<=num;r1++) { for(int c1=1;c1<=r1;c1++) { printf("*"); } for(int s1=r1;s1=1;r2--) { for(int c2=1;c2<=r2;c2++) { printf("*"); } for(int s1=r2;s1

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              What result do you get?

              U 2 Replies Last reply
              0
              • L Lost User

                What result do you get?

                U Offline
                U Offline
                User 11745560
                wrote on last edited by
                #8

                * * ** ** ****** ** ** * *

                L 2 Replies Last reply
                0
                • U User 11745560

                  * * ** ** ****** ** ** * *

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  OK, so just replace the stars with the numbers in each case and you have your result.

                  1 Reply Last reply
                  0
                  • L Lost User

                    What result do you get?

                    U Offline
                    U Offline
                    User 11745560
                    wrote on last edited by
                    #10

                    yes sir the actual result is this #include #include int main() { int num=5; for(int r1=1;r1<=num;r1+=2) { for(int c1=1;c1<=r1;c1++) { printf("%d",r1); } for(int s1=r1;s1=1;r2-=2) { for(int c2=1;c2<=r2;c2++) { printf("%d",r2); } for(int s1=r2;s1

                    1 Reply Last reply
                    0
                    • U User 11745560

                      * * ** ** ****** ** ** * *

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      Your loop values are slightly off. You should be counting 1 - 3 - 5 - 3 - 1, and printing the numeric values in each line rather than stars. Your main loops should be something like:

                      int num = 5;
                      int index;
                      // go from 1 to 5
                      for (index = 1; index <= num; index += 2)
                      {
                      // print the first set of values
                      printf("%d\n", index); // just to show the number
                      }
                      // already printed the 5 set, so go from 3 to 1
                      for (index = num - 2; index > 0; index -= 2)
                      {
                      // print the last set of values
                      printf("%d\n", index);
                      }

                      U 1 Reply Last reply
                      0
                      • L Lost User

                        Your loop values are slightly off. You should be counting 1 - 3 - 5 - 3 - 1, and printing the numeric values in each line rather than stars. Your main loops should be something like:

                        int num = 5;
                        int index;
                        // go from 1 to 5
                        for (index = 1; index <= num; index += 2)
                        {
                        // print the first set of values
                        printf("%d\n", index); // just to show the number
                        }
                        // already printed the 5 set, so go from 3 to 1
                        for (index = num - 2; index > 0; index -= 2)
                        {
                        // print the last set of values
                        printf("%d\n", index);
                        }

                        U Offline
                        U Offline
                        User 11745560
                        wrote on last edited by
                        #12

                        Ok sir Thnak's and could you please give some examples to practise in this pattern??

                        L 1 Reply Last reply
                        0
                        • U User 11745560

                          Ok sir Thnak's and could you please give some examples to practise in this pattern??

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          That is an example, your job is to fill in the fine detail. You will learn much more by trying it yourself than if someone else writes it for you. As an exercise you can try different values of num also.

                          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