Reverse the dispaly?

Posted on 1997-11-15
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 */


{       int a[22];
      int index;

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

      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]);

Question by:patricd
  • 2

Expert Comment

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


Author Comment

ID: 1256334
this worked like a charm...thanks

Accepted Solution

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

patricd, I am answering this for points


Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
port mapped I/o query 10 207
Having a file "symlink" to a memory location (Windows) 6 180
undefined reference to `bswap_128' 9 175
Fill Null values 5 28
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

821 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