Question

With the use of Algorithm explain the following terms: How to analyze a pre condition i.e....

With the use of Algorithm explain the following terms: How to analyze a pre condition i.e. starting state and post condition i.e. ending state in an algorithm

0 0
Add a comment Improve this question Transcribed image text
Answer #1

So we will write a simple algorithm for fibonaaci to make you understand how to analyze a pre condition i.e. starting state and post condition i.e. ending state in an algorithm.

In Fibonaaci sequence the first and second digit is 0 and 1 and the consecutive digits are sum of previous 2 digits.

The pattern looks likes below

0 1 1 2 3 5 8 ......

So the start condition is i=0 and the last condition is n(as we need to print n digits)

Let take array for storing digits a[n], n is the number of digits

for(int i=0;i<n;i++){ //Initialized the llop from i=0 to i=n with incrment i with 1

if(i==0||i==1) // if i is 0 or 1 set array to that value

a[i]=i;

else

a[i]=a[i-1]+a[i-2]; //else set the value to sum of previous two values

}

SO to analyze the start condition check what is the starting of the output, how we can obtain it, to check last condition either check number of digits to be printed.

Add a comment
Know the answer?
Add Answer to:
With the use of Algorithm explain the following terms: How to analyze a pre condition i.e....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT