12,298,463 members (50,610 online)
Rate this:
See more:
1st line- 2 10 30 68 130
2nd line- 1 2 3 5 8 13 21 34 55
3rd line- 1 4 7 10 13 16 19 22 25

please only use for loop for this as my teacher gave a task

```#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
for(a=1;a<=25;a+=3)
{
printf("\n\t3rd line:%d",a);
}
for(b=2;b<=55;b++)
b+=3;
c=b+10;
{
printf("\n\t\t\t:2nd:%d\n%d",b,c);
}

getch();
```
i just wrote this one , it gives 3rd line correctly but what about the 1st two lines they are'nt that simple.
Posted 3-Dec-12 2:37am
jahanxb327
Edited 3-Dec-12 3:28am
v4

Rate this:

## Solution 4

```#include<stdio.h>
main()
{

int a=1,b=1,i,c;

printf("2nd line :");
for(i=0;i<9;i++)
{
c=a;
a=b;
b=c+b;
printf("%d ",a);
}
printf("\n");

printf("1st line :");
for(i=1;i<6;i++)
{
printf("%d ",(i*i*i)+i);

}
printf("\n");

printf("3rd line :");
for(a=1;a<=25;a+=3)
{
printf("%d ",a);
}
printf("\n");

}```
Rate this:

## Solution 1

Your teacher gave the task to you. At least make an effort to solve it.
jahanxb 3-Dec-12 8:48am

@richard i know this is cheating but at least i should have something to get an idea . i am not a freaking genious :p
Richard MacCutchan 3-Dec-12 8:51am

You don't need to be a genius to write a few simple loops. And if you do not even know that much then I suggest you go back and read your course notes.
jahanxb 3-Dec-12 8:55am

right now i am doing that :p
Rate this:

## Solution 2

To understand those series, there is one trick which works well: form the first differences (i.e. b-a, c-b, d-c, e-d...) and observe.

If you can't find a regularity, then repeat the process, forming the second differences, and so on.

This will allow you to figure out a formula or a computational procedure.

v2
jahanxb 3-Dec-12 8:55am

well i am gonna try it , but my teacher said no use of condtions and less number of variables
YvesDaoust 3-Dec-12 9:10am

In what way does this contradict my suggestion ???

1 and 3 can be done with a single variable; 2 requires two of them.
Rate this:

## Solution 3

1. Set the start value to the first number in the sequence.
2. Display the current value of the sequence.
3. If current value equals last number, quit.
4. Calculate the next number in the sequence.
5. Go back to step 2 and repeat.
jahanxb 3-Dec-12 8:58am

#include
#include
void main()
{
int a,b,c;
for(a=1;a<=25;a+=3)

{ printf("\n\t3rd line:%d",a);
}
for(b=2;b<=55;b++)
b+=3;
c=b+10;
{

printf("\n\t\t\t:2nd:%d\n%d",b,c);
}

getch();

i just wrote this one , it gives 3rd line correctly but what about the 1st two lines they are'nt that simple
Richard MacCutchan 3-Dec-12 9:21am

It took me less than a minute with Google to find the answer to the line 1 problem. Or you could find a fellow student who understands mathematics and ask them (Hint: it's a simple polynomial).

Top Experts
Last 24hrsThis month
 OriginalGriff 251 CPallini 205 Richard MacCutchan 164 George Jonsson 160 Sergey Alexandrovich Kryukov 122
 OriginalGriff 9,495 ppolymorphe 5,516 CHill60 5,296 Karthik Bangalore 4,966 Richard MacCutchan 4,874