Solved

Reverse the dispaly?

Posted on 1997-11-15
3
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

688 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