Solved

Reverse the dispaly?

Posted on 1997-11-15
3
198 Views
Last Modified: 2010-04-15
how do I reverse the order of display numbers using the values stored in the array. The code listed below works fine in ascending order but acn seem to get the puppy to reverse.
/* Fibonacci Series */
/* Assignment 8 */

main()

{       int a[22];
      int index;

      a[0] = 0;
      a[1] = 1;

      printf("Fibonacci\n");
      printf("a[ 0] = %5d\n", a[0]);
      printf("a[ 1] = %5d\n", a[1]);

      for (index=2; index < 22; index++)

      {
            printf("a[%2d] = ", index);
            a[index] = a[index-1] + a[index-2];
            printf("%5d   ", a[index]);
            printf("%5d   ", a[index] - a[index-1]);
            printf("%f\n", (float) a[index] / (float) a[index-1]);
      }

}
thanks
0
Comment
Question by:patricd
  • 2
3 Comments
 
LVL 2

Expert Comment

by:wpinto
ID: 1256333
Hi patricd,

I'm not sure I understand what you are trying to say. Do you just want to display the no in the array in descending order??

If so, you could do this easily using the following loop. Add this code at the end

printf("Fibonacci - in reverse\n");

for (index=21; index > 1; index--)
{
printf("a[%2d] = ", index);
printf("%5d ", a[index]);
printf("%5d ", a[index] - a[index-1]);
printf("%f\n", (float) a[index] / (float) a[index-1]);
}

printf("a[ 1] = %5d\n", a[1]);
printf("a[ 0] = %5d\n", a[0]);

Hope this helps. If this is not what you are looking, lemme know

Wilfred
0
 

Author Comment

by:patricd
ID: 1256334
this worked like a charm...thanks
0
 
LVL 2

Accepted Solution

by:
wpinto earned 50 total points
ID: 1256335
Refer to my comment for the answer

patricd, I am answering this for points

Thanks,
Wilfred
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now