Please any one answer thease questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • surendra27
    New Member
    • Sep 2006
    • 4

    Please any one answer thease questions

    Please any one provide the logic for these out puts


    [html]
    [pre]

    Q1)

    0
    12
    345
    6789

    Q2)

    0
    21
    543
    9876

    Q3)
    0
    101
    21012
    3210123
    432101234
    3210123
    21012
    101
    0
    [/pre]
    [/html]
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    A homeowrk question if ever I saw one.

    Do you not see any pattern to numbers?

    In question 1 try putting the numbers on a single line

    How does this apply to question 2?

    In question 3 look at the columns of numbers created. What do you notice?

    Comment

    • surendra27
      New Member
      • Sep 2006
      • 4

      #3
      I try to solve these questions
      but i coudn't
      which was asked my teacher in yesterday class..

      pls help me...

      Comment

      • plumpnation
        New Member
        • Sep 2006
        • 16

        #4
        at a brief glance, question one is not only vertical but diagonal too. e.g. plus two, plus three, plus four

        0+2 = 2
        2+3 = 5
        5+4 = 9

        Comment

        • plumpnation
          New Member
          • Sep 2006
          • 16

          #5
          silly me, just listen to banfa

          Comment

          • risby
            New Member
            • Sep 2006
            • 30

            #6
            Originally posted by surendra27
            Please any one provide the logic for these out puts


            [html]
            [pre]

            Q1)

            0
            12
            345
            6789

            Q2)

            0
            21
            543
            9876

            Q3)
            0
            101
            21012
            3210123
            432101234
            3210123
            21012
            101
            0
            [/pre]
            [/html]
            I can't help wondering if you and durini ali attend the same class.

            Anyway, is this the kind of logic you are looking for?
            Code:
            #include <stdio.h>
            #include <string.h>
            
            int main(int argc, char ** argv)
            {
            	int r = 0;
            	int i;
            	int first;
            	char digits[] = "0123456789";
            
            /* print consecutive digits in lines of increasing width */
            	for (i=first=0; first+i<(int)strlen(digits)+1; i++, first += i)
            	{
            		printf("%*.*s\n", i+1, i+1, &digits[first]);
            	}
            	printf("\n");
            
            	return r;
            }

            Comment

            • risby
              New Member
              • Sep 2006
              • 30

              #7
              Originally posted by risby
              Anyway, is this the kind of logic you are looking for?
              Hmmm, I forgot to right-justify the strings. How about this:

              Code:
              #include <stdio.h>
              #include <string.h>
              
              int main(int argc, char ** argv)
              {
              	int r = 0;
              	int i;
              	int first;
              	int width;
              	char digits[] = "0123456789";
              
              /* calculate maximum width */
              	for (i=first=0; first+i<(int)strlen(digits)+1; i++, first += i)
              	{
              		width=i+1;;
              	}
              
              /* print consecutive digits in lines of increasing width */
              	for (i=first=0; first+i<(int)strlen(digits)+1; i++, first += i)
              	{
              		printf("%*.*s\n", width, i+1, &digits[first]);
              	}
              
              	return r;
              }

              Comment

              Working...