Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C GimmeCode Homework
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 Frown | :(
 

#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 3:37am
jahanxb327
Edited 3-Dec-12 4:28am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

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");
 
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your teacher gave the task to you. At least make an effort to solve it.
  Permalink  
Comments
jahanxb at 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 at 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 at 3-Dec-12 8:55am
   
right now i am doing that :p
Rate this: bad
good
Please Sign up or sign in to vote.

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.
 
Last hint: start with the third.
  Permalink  
v2
Comments
jahanxb at 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 at 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: bad
good
Please Sign up or sign in to vote.

Solution 3

Think about what you are trying to do in your loops.
  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.
  Permalink  
Comments
jahanxb at 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 at 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).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100