generate number

• 05-03-2010
cheeta
for loop
Code:

```#include<stdio.h> //main function.. int main(void){ int i,j,k; int n=3;         for(i=0;i<=3;i++) {                 j=1;                 while(j<=n) {                         printf("\t%d",j);                         j++;                 }                 printf("\n");                 n=n+3;         } }```
the output is:
1 2 3
1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10 11 12

but i want the output as
1 5
2 6 9
3 7 10 12
4 8 11 13 14 15
anyone help me using the for loop?..
• 05-03-2010
claudiu
Well if you care to explain what you are trying to do, sure, why not?
• 05-03-2010
cheeta
thanks claudiu, for ur reply i am actually new to c...i actually need the output as :
1
2 5 8
3 6 9 11 13
4 7 10 12 14 15
• 05-03-2010
claudiu
Okay, so if you had say, 20 numbers what would be the pattern then? I am just a little confused on what you are actually trying to do.
• 05-03-2010
cheeta
help me with this 15 numbers...
• 05-03-2010
laserlight
I can guess what the pattern is, but I agree with claudiu: you need to express this pattern yourself. Do it in words, then it may become easier to translate it to code.

Just helping you with "this 15 numbers" is not the right approach, since obviously the simple solution for this is to print the sequence as-is, without the use of loops. But to understand how to solve this with loops means understanding the general pattern.
• 05-03-2010
cheeta
like,if the number is 20,it has to be like

1 5
2 6 9 12
3 7 10 13 15 17
4 8 11 14 16 18 19 20

see,the thing is it has to be with 4 rows alone...
• 05-03-2010
hawaiian robots
Your not explaining the pattern... all your doing is showing us a bunch of numbers...

Explain, using words, what the pattern is, then perhaps we can help.
• 05-03-2010
cheeta
hey guys,sorry guys i dono to explain it...but atlast ,i cud do it myself...This is the program :
Code:

```for(i=1; i<=limit; i++) {     printf("%d", i);     for(j=1; j<i; j++)     {         k=1;         sub = j * limit;         while(k <= j)         {             sub = sub - k;             k++;         }         printf("    %d", (i+sub));     }     printf("\n"); }```
• 05-03-2010