C Code to print following series

H

Harshal Jain

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

010201130311240
512223141550815233244518.......

Thanks!
 
R

Ralf Damaschke

Harshal Jain said:
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;
]


My pleasure.
 
J

jacob navia

Le 09/08/11 12:08, Ralf Damaschke a écrit :
Harshal Jain said:
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;
]


My pleasure.


Shorter:

#include<stdio.h>
int main (int argc, char **argv)
{
puts("010201130311240512223141550815233244518");
}
 
B

Ben Bacarisse

Harshal Jain said:
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.
 
M

Mark Bluemel

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?
 
M

Michael Press

Ben Bacarisse said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top