• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Reverse the dispaly?

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
patricd
Asked:
patricd
  • 2
1 Solution
 
wpintoCommented:
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
 
patricdAuthor Commented:
this worked like a charm...thanks
0
 
wpintoCommented:
Refer to my comment for the answer

patricd, I am answering this for points

Thanks,
Wilfred
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now