[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

C Code to print following series

Harshal Jain

8/9/2011 8:20:00 AM

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

010201130311240
512223141550815233244518.......

Thanks!
8 Answers

phrogg

8/9/2011 8:35:00 AM

0

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

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


Homework ?

Ralf Damaschke

8/9/2011 10:09:00 AM

0

Harshal Jain <harshaldjain@gmail.com> 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[i] : '.';
if (isdigit(c)) /* c values guaranteed to be positive */
putchar(c);
}
putchar('\n');
return 0;
]


> Thanks!

My pleasure.

jacob navia

8/9/2011 10:23:00 AM

0

Le 09/08/11 12:08, Ralf Damaschke a écrit :
> Harshal Jain<harshaldjain@gmail.com> 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[i] : '.';
> 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");
}

daniele

8/9/2011 12:25:00 PM

0

Mickey Mouse <fake@email.com> writes:

> On Tue, 9 Aug 2011 01:20:13 -0700 (PDT), Harshal Jain
> <harshaldjain@gmail.com> 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

Ben Bacarisse

8/9/2011 9:42:00 PM

0

Harshal Jain <harshaldjain@gmail.com> 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.o... and C is http://oeis.o...
the sequences B and D are related to A and C but the OP's sequence is
somewhere between A and B.

--
Ben.

Mark Bluemel

8/10/2011 12:49:00 PM

0

On 08/09/2011 10:41 PM, Ben Bacarisse wrote:
> Harshal Jain<harshaldjain@gmail.com> 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.o... and C is http://oeis.o...
> 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?

Ben Bacarisse

8/10/2011 4:24:00 PM

0

Mark Bluemel <mark_bluemel@pobox.com> writes:

> On 08/09/2011 10:41 PM, Ben Bacarisse wrote:
>> Harshal Jain<harshaldjain@gmail.com> 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.o... and C is http://oeis.o...
>> 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.

Michael Press

8/10/2011 8:31:00 PM

0

In article
<0.42eeaf6cf8080ed1e67a.20110809224134BST.87r54u1cvl.fsf@bsb.me.uk>,
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

> Harshal Jain <harshaldjain@gmail.com> 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.o... and C is http://oeis.o...
> 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