Link to home
Start Free TrialLog in
Avatar of patricd
patricd

asked on

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
Avatar of wpinto
wpinto

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
Avatar of patricd

ASKER

this worked like a charm...thanks
ASKER CERTIFIED SOLUTION
Avatar of wpinto
wpinto

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial