Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10954 > unrolled thread

Request for help

Started bygpy5504@hotmail.com
First post2011-10-17 22:55 -0700
Last post2011-10-18 12:54 -0700
Articles 8 — 5 participants

Back to article view | Back to comp.lang.c++


Contents

  Request for help gpy5504@hotmail.com - 2011-10-17 22:55 -0700
    Re: Request for help Ian Collins <ian-news@hotmail.com> - 2011-10-18 20:00 +1300
      Re: Request for help gpy5504@hotmail.com - 2011-10-18 00:30 -0700
        Re: Request for help Juha Nieminen <nospam@thanks.invalid> - 2011-10-18 08:22 +0000
        Re: Request for help Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-18 03:41 -0700
    Re: Request for help Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-18 02:51 -0700
      Re: Request for help Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-23 06:21 -0700
    Re: Request for help red floyd <no.spam.here@its.invalid> - 2011-10-18 12:54 -0700

#10954 — Request for help

Fromgpy5504@hotmail.com
Date2011-10-17 22:55 -0700
SubjectRequest for help
Message-ID<200f3cee-b57e-4fe6-a70c-8f27029deb34@13g2000prp.googlegroups.com>
1. Write a program which prompts the user to enter an integer between
1 and 9.
Based on the inputted number, the program outputs a triangular textual
shape using digits
(see below).
Sample Execution:
Enter N: 5
12345
1234
123
12
1

2.1. The Fibonacci sequence is a sequence of numbers beginning
1, 1, 2, 3, 5, 8, 13, 21, ...
The first two elements are defined to be 1. Each of the other elements
is the sum of its
two predecessors. Write a program that takes a value for N in the
range 1 to 30 and
displays the first N elements of the Fibonacci sequence.
Sample Execution:
Enter N: 9
Fibonacci sequence: 1 1 2 3 5 8 13 21 34

2. An integer P is called a prime number if the only positive integers
that divide P are
1 and P itself. Write a program which inputs a number N between 2 and
100 and then
loops through integers 2 to N and displays only those numbers which
are prime.
Sample Execution:
Enter N: 15
2 3 5 7 11 13

[toc] | [next] | [standalone]


#10955

FromIan Collins <ian-news@hotmail.com>
Date2011-10-18 20:00 +1300
Message-ID<9g4mh2FkohU1@mid.individual.net>
In reply to#10954
On 10/18/11 06:55 PM, gpy5504@hotmail.com wrote:
> 1. Write a program which prompts the user to enter an integer between
> 1 and 9.
> Based on the inputted number, the program outputs a triangular textual
> shape using digits
> (see below).
> Sample Execution:
> Enter N: 5
> 12345
> 1234
> 123
> 12
> 1
>
> 2.1. The Fibonacci sequence is a sequence of numbers beginning
> 1, 1, 2, 3, 5, 8, 13, 21, ...
> The first two elements are defined to be 1. Each of the other elements
> is the sum of its
> two predecessors. Write a program that takes a value for N in the
> range 1 to 30 and
> displays the first N elements of the Fibonacci sequence.
> Sample Execution:
> Enter N: 9
> Fibonacci sequence: 1 1 2 3 5 8 13 21 34
>
> 2. An integer P is called a prime number if the only positive integers
> that divide P are
> 1 and P itself. Write a program which inputs a number N between 2 and
> 100 and then
> loops through integers 2 to N and displays only those numbers which
> are prime.
> Sample Execution:
> Enter N: 15
> 2 3 5 7 11 13

Where's you code?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#10956

Fromgpy5504@hotmail.com
Date2011-10-18 00:30 -0700
Message-ID<3016a6e9-03ed-4774-8e38-c1a0670530cd@t38g2000prg.googlegroups.com>
In reply to#10955
i need to write out the program by myself.
for question 3. i m writting the system as :
if (N_fibonacci == 1 )
current = previous1;

else if (N_fibonacci ==1)
current = previous2;

else {
counter= 3;
while (counter <= N fibonacci)
{
current = previous1 + previous2
previous1 = previous2
previous2 = current;
counter ++;
}

but the answer that program gave me is 1 3 4 5 1 5 3 7 4 and not the
answer that i want which is Fibonacci sequence: 1 1 2 3 5 8 13 21 34.
May i know what are the program.
and the other two questions i do not have any ideas to do  the
programming ..

[toc] | [prev] | [next] | [standalone]


#10959

FromJuha Nieminen <nospam@thanks.invalid>
Date2011-10-18 08:22 +0000
Message-ID<4e9d374c$0$4355$7b1e8fa0@news.nbl.fi>
In reply to#10956
gpy5504@hotmail.com wrote:
> i need to write out the program by myself.

  Then why are you asking here?

[toc] | [prev] | [next] | [standalone]


#10966

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-10-18 03:41 -0700
Message-ID<1e0b56d9-269b-4589-b7e1-71fe6eeb2247@e4g2000vbw.googlegroups.com>
In reply to#10956
On Oct 18, 8:30 am, gpy5...@hotmail.com wrote:

> i need to write out the program by myself.

woop-i-doop what will the universities think of next!

When posting code to usenet (ie. here), post a
   1. short
   2. complete
   3. compilable (unless you are having compilation problems)
program that illustrates your problem. You have not posted a complete
program and what you have posted is syntactically incorrect.

> for question 3. i m writting the system as :
> if (N_fibonacci == 1 )
> current = previous1;
>
> else if (N_fibonacci ==1)
> current = previous2;
>
> else {
> counter= 3;
> while (counter <= N fibonacci)
> {
> current = previous1 + previous2
> previous1 = previous2
> previous2 = current;
> counter ++;
>
> }

the layout is hard to follow. better (but still wrong) would have been
this:-

int main ()
{
    if (N_fibonacci == 1 )
        current = previous1;
    else if (N_fibonacci == 1)
        current = previous2;
    else
    {
        counter = 3;
        while (counter <= N fibonacci)
        {
            current = previous1 + previous2;
            previous1 = previous2;
            previous2 = current;
            counter ++;
        }
    }
}

there is no output, none of the variables are defined and there is no
loop. You test if N_fibonacci is equal to 1 twice.

Get a piece of paper and draw 5 colums write "N_fibonacci" at the top
of the first column "previous1" at the head of the second column etc.
Put a question mark under each variable to show they are unitialised.
Then go through the program one line at time and update the columns as
appropriate. Ensure you and the progarm get the same answer. Put extra
printf(0s in to see values as they change. This should give you
insight.

Come back here if you still have problems. And don't post program
fragments again!

> but the answer that program gave me is 1 3 4 5 1 5 3 7 4 and not the
> answer that i want which is Fibonacci sequence: 1 1 2 3 5 8 13 21 34.
> May i know what are the program.
> and the other two questions i do not have any ideas to do  the
> programming ..

write a progarm to print the numbers 1 to 5

[toc] | [prev] | [next] | [standalone]


#10963

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-10-18 02:51 -0700
Message-ID<789d7611-6be0-4872-b9dc-6cfb8dfd80d9@k35g2000yqh.googlegroups.com>
In reply to#10954
On Oct 18, 6:55 am, gpy5...@hotmail.com wrote:
> 1. Write a program which prompts the user to enter an integer between
> 1 and 9.
> Based on the inputted number, the program outputs a triangular textual
> shape using digits
> (see below).
> Sample Execution:
> Enter N: 5
> 12345
> 1234
> 123
> 12
> 1

pseudo code for the problem

(define (print-row n)
    (let loop ((i 1))
        (if (not (zero? i))
            (begin
                (display i)
                (loop (- i 1)) )))
    (print #\newline) )


(define (print-triangle n)
    (if (not (zero? n))
        (print-row n)
        (print-triangle (- n 1)) ))



> 2.1. The Fibonacci sequence is a sequence of numbers beginning
> 1, 1, 2, 3, 5, 8, 13, 21, ...
> The first two elements are defined to be 1. Each of the other elements
> is the sum of its
> two predecessors. Write a program that takes a value for N in the
> range 1 to 30 and
> displays the first N elements of the Fibonacci sequence.
> Sample Execution:
> Enter N: 9
> Fibonacci sequence: 1 1 2 3 5 8 13 21 34
>
> 2. An integer P is called a prime number if the only positive integers
> that divide P are
> 1 and P itself. Write a program which inputs a number N between 2 and
> 100 and then
> loops through integers 2 to N and displays only those numbers which
> are prime.
> Sample Execution:
> Enter N: 15
> 2 3 5 7 11 13

[toc] | [prev] | [next] | [standalone]


#11047

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-10-23 06:21 -0700
Message-ID<6713d786-c5ca-4762-9f2f-8e05b75baf7b@f11g2000vbm.googlegroups.com>
In reply to#10963
On Oct 18, 10:51 am, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
> On Oct 18, 6:55 am, gpy5...@hotmail.com wrote:
>
> > 1. Write a program which prompts the user to enter an integer between
> > 1 and 9.
> > Based on the inputted number, the program outputs a triangular textual
> > shape using digits
> > (see below).
> > Sample Execution:
> > Enter N: 5
> > 12345
> > 1234
> > 123
> > 12
> > 1
>
> pseudo code for the problem
>
> (define (print-row n)
>     (let loop ((i 1))
>         (if (not (zero? i))
>             (begin
>                 (display i)
>                 (loop (- i 1)) )))
>     (print #\newline) )
>
> (define (print-triangle n)
>     (if (not (zero? n))
>         (print-row n)
>         (print-triangle (- n 1)) ))

a version that actuallyworked wouldlook more like this:-

(define (print-row n)
    (let loop ((i 1))
        (if (<= i n)
            (begin
                (display i)
                (loop (+ i 1)) )))
    (display #\newline) )

(define (print-triangle n)
    (if (not (zero? n))
        (begin
            (print-row n)
            (print-triangle (- n 1)) )))

[toc] | [prev] | [next] | [standalone]


#10974

Fromred floyd <no.spam.here@its.invalid>
Date2011-10-18 12:54 -0700
Message-ID<j7klih$fva$1@dont-email.me>
In reply to#10954
On 10/17/2011 10:55 PM, gpy5504@hotmail.com wrote:
> [redacted]

Your answer may be found at 
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web