const int N = 6;
int n1 = 1, n2 = 0;
int i, k, n;
for (k = 0; k < N; ++k) {
n = n1 + n2;
for (i = 1; i <= n; ++i)
printf(" %d",i);
putchar(',');
n1 = n2;
n2 = n;
}
putchar('\n');
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
But I don't want the last set to end with a (,). Could you give me code without the last printed (,)? Pleazzzzzzzzzzz!
Well, srivtsan, finally your hard work of asking here , here , here and over here has payed off. ;)
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
>i was not able to get the idea
>how did you get the idea Arkm ?
Do you know what a Fibonacci number is?
If you haven't grasp that the exercise loses its value.
>i dont know why u want the series to end without a ,
>there is nothing wrong if you get a , after the series is genetrated
>if you want i will modify it and give you!
No, thank you, I was playing. I happened to find your posts in three places I frequent. So I made a search with the series to see if you posted somewhere else, and certainly you did.
I thought you had it for sure after the answer in Yahoo, and the clear clue that Salem gave you at Cboard. ;)
#include <stdio.h>
const size_t fibonacci(const size_t n);
void display(const size_t m);
int main(void)
{
display(6);
return 0;
}
const size_t fibonacci(const size_t n)
{
return (n < 2 ? n : fibonacci(n-1) + fibonacci(n-2));
}
void display(const size_t m)
{
size_t n;
for (n = 1; n <= m; n++) {
size_t j, f;
f = fibonacci(n);
for (j = 1; j <= f; ++j)
printf("%d", j);
if (n != m)
putchar(',');
}
}
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218