My college programming teacher gave me this pseudocode assignment on his first lecture. For crying out loud i have never heard anything like that. Actually am suppose to
Write a pseudocode to generate the
1) fabonacii series &
2) prime numbers btw 1 & 50.

-Note that there are two separate pseudocodes
to be written.
.....from my research made i guess am suppose to write in a flowchart form since i know the The Fabonacii series is 1, 1, 2, 3, 5, 8, 13, 21, 34, ... i am just confused....i need help,please!!!!

pseudocode and flow charts are two different things. see link for description and brief examples.

To get to the pseudocode level try writing out how to generate a fibonacci series from 1 to 50 and how to determine if a number above zero and under 51 is prime. Then try to shape the narative description into variables and things you do to or with variables such as control loops, if/else statements, functions, or whatever else you know about, without using the precise syntax of written code.

Frequently, when presented with a new task/assignment, it is necessary to do some research to get background on the problem. That you've done some research on the Fibonacci series is to your credit. Now try to determine how to generate the series you have presented given the first two numbers are 1 and 1.

Hey, am very grateful to you all for the contributions. Lerner,thanks a bunch, cos u really made me try to get the logic behind d fabonacii series.Even after giving up.Now i know how to get the other nos in d series but my problem is outlinin it in the if-else format.

Member Avatar for iamthwee
if summat Then
  //do crap
endif

And so on.

Hey, am very grateful to you all for the contributions. Lerner,thanks a bunch, cos u really made me try to get the logic behind d fabonacii series.Even after giving up.Now i know how to get the other nos in d series but my problem is outlinin it in the if-else format.

Outlining it in if/else format isn't strictly necessary - Remember that Pseudocode is supposed to mimic a simplified version of the english language(or whatever other language the programmer would speak naturally) at an appropriate level of detail, so that the pseudocode can be easily translated into a program.

for example, pseudocode for going to the supermarket might be something like

Walk to car
if ( car locked )
    unlock car
end if
get in car
fasten seatbelt
start engine
drive to supermarket
if ( supermarket closed )
    go home
else
    go shopping
end if

One approach to solving your problem could be to work out how you calculate the fibonnaci sequence on paper, and make a note of every small step you make along the way, including the data you're holding, your processes/calculations, and the results. When you've done it for several numbers in the series, you'll notice patterns emerging.

Step 1)
Given that 1 and 1 are the first two fibonacci numbers---there is no way to figure this part out, you just have to know it or look it up some how.

Step 2)
Given the list of fibonacci numbers you have, prove to yourself that each fibonacci number beyond the first two fibonacci numbers, 1 and 1, is the sum of the preceding two fibonacci numbers.

Step 3)
Now, if you have three fibonacci numbers, currentFib, priorFib and beforePriorFib where currentFib is defined to be the current fibonacci number, priorFib is the fibonacci number just prior to the current fibonacci number and beforePriorFib is the fibonacci number just before priorFib and each currentFib equals priorFib plus beforePriorFib. Not only that, but each subsequent currentFib can be calculated from the current currentFib and the current priorFib if you reassign the current values where needed.

Step 4)
While currentFib is less than 50
//I'll let you do the rest of the pseudocode

HEY, U GUYS ARE DA BOMB!!!!!!!!!!!
Thanks yall, i mean u really have made my day
yours in pseudocodes
syruspayne

Member Avatar for iamthwee

Try incorporating this into your pseudo code.:lol:

[tex]F_{n}=\frac{(1+sqrt{5})^{n}-(1-sqrt{5})^{n}}{2^{n}sqrt{5}}[/tex]

hey yall,i think i got the sourcecode for the primenos problem.now my difficulty is writtin the pseudocode,because the program is suppose to generate not something to test inputs if they are prime nos.

I need some help with starting,Thanks

#include <stdio.h>
int main (void)
{
 int   p, d;
 _Bool isPrime;

 for ( p = 2; p <= 50; ++p ) {
     isPrime = 1;
     for ( d = 2; d < p; ++d )
    if ( p % d  == 0 )
       isPrime = 0;
          if ( isPrime != 0 )
       printf ("%i ",p);
}
 printf ("\n");
 return 0;
}

Thanks a lot,but the sieve of atkin is very complex and compilcated in my own point of view.All i just require is to guide me in changing my source code to pseudocode.Yours

Member Avatar for iamthwee

But the pseudo code for the sieve of Atkin is written for you. All you have to do is copy it on paper and hand it in.

But the pseudo code for the sieve of Atkin is written for you. All you have to do is copy it on paper and hand it in.

I wouldn't do that. Most institutions have rules against plagiarism & cheating. Copying & pasting directly from a website is almost certainly going to breach those rules.

It sounds to me as if the original poster has already solved the problem and just needs to rewrite it into a design document with pseudocode - so chances are, that wouldn't be much help anyway (unless his code is directly based on the sieve of atkin).

changing source code to pseudocode is easy! You don't need to say anything about libraries or data types, and you can also ignore certain rules on scope too - just translate each line or block of code into simplified english.

for example, a C++ program that prints all even numbers from 0 to 10 might look like

#include <iostream>

int main()
{
    for(int i(0); i!=10; ++i)
        if( i % 2 == 0)
           std::cout << i << " is even." << std::endl;
}

The pseudocode could look like this..

for N = 0 to 10 do
    if ( N / 2 has no remainder )
        write ( N " is even" )
    end if
end for

In the pseudocode, there's no need to explain minor details such as how you express N/2 having no remainder, or how you are going to 'write' something to the screen. The important part is the algorithm and not the syntax!

Psuedocode is usually part of the design phase, before any implementation decisions are made - this means it will be fairly generic. it could be implemented using any language, eg VB, C, Java, Ruby, Python, etc...

There are all sorts of ways to write psuedocode - some people/companies have published their own standards for other people to use (although no single one is generally accepted as 'the' standard), or you can make your own standard up. The only important thing really is to be consistent. have a look here for more info: http://en.wikipedia.org/wiki/Pseudocode

Yeah, Thanks a lot.

Member Avatar for iamthwee

I wouldn't do that. Most institutions have rules against plagiarism & cheating.

Good point! in that case you will prolly have to change a few words around to try and trick your teacher. :idea:

But I gave you the equation for the fibonacci sequence which you can use in your pseudo code. Good luck.

for example, pseudocode for going to the supermarket might be something like

Walk to car
if ( car locked )
    unlock car
end if
get in car
fasten seatbelt
start engine
drive to supermarket
if ( supermarket closed )
    go home
else
    go shopping
end if

Very easy to understand when you put it like that, great stuff !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.