C Code to print following series

Discussion in 'C Programming' started by Harshal Jain, Aug 9, 2011.

  1. Harshal Jain

    Harshal Jain Guest

    Find out the pattern and write a C program to print it upto n
    digits...

    010201130311240
    512223141550815233244518.......

    Thanks!
     
    Harshal Jain, Aug 9, 2011
    #1
    1. Advertising

  2. Harshal Jain

    Mickey Mouse Guest

    On Tue, 9 Aug 2011 01:20:13 -0700 (PDT), Harshal Jain
    <> wrote:

    >Find out the pattern and write a C program to print it upto n
    >digits...
    >
    >010201130311240
    >512223141550815233244518.......
    >
    >Thanks!



    Homework ?
     
    Mickey Mouse, Aug 9, 2011
    #2
    1. Advertising

  3. Harshal Jain <> wrote:

    > Find out the pattern and write a C program to print it upto n
    > digits...
    >
    > 010201130311240
    > 512223141550815233244518.......



    #include <stdlib.h>
    #include <stdio.h>
    #include <ctype.h>
    int main (int argc, char **argv)
    {
    char *seq = "010201130311240512223141550815233244518";
    int n = argc > 1 ? atoi(argv[1]) : 0;
    for (int i = 0; i < n; i++) {
    int c = i < (sizeof seq - 1) ? seq : '.';
    if (isdigit(c)) /* c values guaranteed to be positive */
    putchar(c);
    }
    putchar('\n');
    return 0;
    ]


    > Thanks!


    My pleasure.
     
    Ralf Damaschke, Aug 9, 2011
    #3
  4. Harshal Jain

    jacob navia Guest

    Le 09/08/11 12:08, Ralf Damaschke a écrit :
    > Harshal Jain<> wrote:
    >
    >> Find out the pattern and write a C program to print it upto n
    >> digits...
    >>
    >> 010201130311240
    >> 512223141550815233244518.......

    >
    >
    > #include<stdlib.h>
    > #include<stdio.h>
    > #include<ctype.h>
    > int main (int argc, char **argv)
    > {
    > char *seq = "010201130311240512223141550815233244518";
    > int n = argc> 1 ? atoi(argv[1]) : 0;
    > for (int i = 0; i< n; i++) {
    > int c = i< (sizeof seq - 1) ? seq : '.';
    > if (isdigit(c)) /* c values guaranteed to be positive */
    > putchar(c);
    > }
    > putchar('\n');
    > return 0;
    > ]
    >
    >
    >> Thanks!

    >
    > My pleasure.
    >


    Shorter:

    #include<stdio.h>
    int main (int argc, char **argv)
    {
    puts("010201130311240512223141550815233244518");
    }
     
    jacob navia, Aug 9, 2011
    #4
  5. Harshal Jain

    daniele.g Guest

    Mickey Mouse <> writes:

    > On Tue, 9 Aug 2011 01:20:13 -0700 (PDT), Harshal Jain
    > <> wrote:
    >
    >>Find out the pattern and write a C program to print it upto n
    >>digits...
    >>
    >>010201130311240
    >>512223141550815233244518.......
    >>
    >>Thanks!

    >
    >
    > Homework ?


    I suppose.
    --
    - Ai bambini buoni, la dolce Euchessina.
    - E a quelli cattivi?
    - Che spingano!
    -- Anonimo
     
    daniele.g, Aug 9, 2011
    #5
  6. Harshal Jain <> writes:

    > Find out the pattern and write a C program to print it upto n
    > digits...
    >
    > 010201130311240
    > 512223141550815233244518.......


    I can't work out what this sequence is, though I am pretty sure I know
    what sort of sequence it is. I would expect any of these:

    A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,5,0,6,1,5,2,3,3,1,4...
    B 0,1,0,1,1,2,0,3,1,1,2,1,3,3,0,6,1,2,2,3,3,4,0,7,1,4,2,5,3,2,4...
    C 0,1,0,1,1,2,0,1,2,3,1,3,0,2,3,2,2,5,1,4,0,1,5,1,4,3,3,5,2,6,1...
    D 0,1,0,1,1,2,0,1,2,4,1,3,0,1,4,1,3,2,2,7,1,4,0,3,4,3,3,4,2,8,1...

    The closest match, A, differs here:

    A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3, 5,0,6,1,5,2,3,3,1,4...
    0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,1,4,1,5,5,0,8,1,5,2,3,3,2,4...

    I suspect a typo but maybe someone has worked it out?

    Spoiler: A is http://oeis.org/A055186 and C is http://oeis.org/A079686
    the sequences B and D are related to A and C but the OP's sequence is
    somewhere between A and B.

    --
    Ben.
     
    Ben Bacarisse, Aug 9, 2011
    #6
  7. Harshal Jain

    Mark Bluemel Guest

    On 08/09/2011 10:41 PM, Ben Bacarisse wrote:
    > Harshal Jain<> writes:
    >
    >> Find out the pattern and write a C program to print it upto n
    >> digits...
    >>
    >> 010201130311240
    >> 512223141550815233244518.......

    >
    > I can't work out what this sequence is, though I am pretty sure I know
    > what sort of sequence it is. I would expect any of these:
    >
    > A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,5,0,6,1,5,2,3,3,1,4...
    > B 0,1,0,1,1,2,0,3,1,1,2,1,3,3,0,6,1,2,2,3,3,4,0,7,1,4,2,5,3,2,4...
    > C 0,1,0,1,1,2,0,1,2,3,1,3,0,2,3,2,2,5,1,4,0,1,5,1,4,3,3,5,2,6,1...
    > D 0,1,0,1,1,2,0,1,2,4,1,3,0,1,4,1,3,2,2,7,1,4,0,3,4,3,3,4,2,8,1...
    >
    > The closest match, A, differs here:
    >
    > A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3, 5,0,6,1,5,2,3,3,1,4...
    > 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,1,4,1,5,5,0,8,1,5,2,3,3,2,4...
    >
    > I suspect a typo but maybe someone has worked it out?
    >
    > Spoiler: A is http://oeis.org/A055186 and C is http://oeis.org/A079686
    > the sequences B and D are related to A and C but the OP's sequence is
    > somewhere between A and B.


    Is there a practical use for such sequences or are they just an
    interesting exercise?
     
    Mark Bluemel, Aug 10, 2011
    #7
  8. Mark Bluemel <> writes:

    > On 08/09/2011 10:41 PM, Ben Bacarisse wrote:
    >> Harshal Jain<> writes:
    >>
    >>> Find out the pattern and write a C program to print it upto n
    >>> digits...
    >>>
    >>> 010201130311240
    >>> 512223141550815233244518.......

    >>
    >> I can't work out what this sequence is, though I am pretty sure I know
    >> what sort of sequence it is. I would expect any of these:
    >>
    >> A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,5,0,6,1,5,2,3,3,1,4...
    >> B 0,1,0,1,1,2,0,3,1,1,2,1,3,3,0,6,1,2,2,3,3,4,0,7,1,4,2,5,3,2,4...
    >> C 0,1,0,1,1,2,0,1,2,3,1,3,0,2,3,2,2,5,1,4,0,1,5,1,4,3,3,5,2,6,1...
    >> D 0,1,0,1,1,2,0,1,2,4,1,3,0,1,4,1,3,2,2,7,1,4,0,3,4,3,3,4,2,8,1...
    >>
    >> The closest match, A, differs here:
    >>
    >> A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3, 5,0,6,1,5,2,3,3,1,4...
    >> 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,1,4,1,5,5,0,8,1,5,2,3,3,2,4...
    >>
    >> I suspect a typo but maybe someone has worked it out?
    >>
    >> Spoiler: A is http://oeis.org/A055186 and C is http://oeis.org/A079686
    >> the sequences B and D are related to A and C but the OP's sequence is
    >> somewhere between A and B.

    >
    > Is there a practical use for such sequences or are they just an
    > interesting exercise?


    I don't know of any use for them.

    --
    Ben.
     
    Ben Bacarisse, Aug 10, 2011
    #8
  9. In article
    <>,
    Ben Bacarisse <> wrote:

    > Harshal Jain <> writes:
    >
    > > Find out the pattern and write a C program to print it upto n
    > > digits...
    > >
    > > 010201130311240
    > > 512223141550815233244518.......

    >
    > I can't work out what this sequence is, though I am pretty sure I know
    > what sort of sequence it is. I would expect any of these:
    >
    > A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,5,0,6,1,5,2,3,3,1,4...
    > B 0,1,0,1,1,2,0,3,1,1,2,1,3,3,0,6,1,2,2,3,3,4,0,7,1,4,2,5,3,2,4...
    > C 0,1,0,1,1,2,0,1,2,3,1,3,0,2,3,2,2,5,1,4,0,1,5,1,4,3,3,5,2,6,1...
    > D 0,1,0,1,1,2,0,1,2,4,1,3,0,1,4,1,3,2,2,7,1,4,0,3,4,3,3,4,2,8,1...
    >
    > The closest match, A, differs here:
    >
    > A 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3, 5,0,6,1,5,2,3,3,1,4...
    > 0,1,0,2,0,1,1,3,0,3,1,1,2,4,0,5,1,2,2,2,3,1,4,1,5,5,0,8,1,5,2,3,3,2,4...
    >
    > I suspect a typo but maybe someone has worked it out?
    >
    > Spoiler: A is http://oeis.org/A055186 and C is http://oeis.org/A079686
    > the sequences B and D are related to A and C but the OP's sequence is
    > somewhere between A and B.


    I coded A055186. It was fun.

    --
    Michael Press
     
    Michael Press, Aug 10, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shraddha
    Replies:
    10
    Views:
    458
    James Kanze
    May 26, 2007
  2. Shraddha
    Replies:
    4
    Views:
    260
    James Kanze
    May 26, 2007
  3. keto
    Replies:
    0
    Views:
    964
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    363
    David Cournapeau
    Dec 30, 2008
  5. ÕÔ±û·å

    why the following HereDoc print don't work?

    ÕÔ±û·å, Dec 8, 2004, in forum: Perl Misc
    Replies:
    29
    Views:
    290
    Sherm Pendley
    Dec 20, 2004
Loading...

Share This Page