How to output an array backward ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • binarylife
    New Member
    • Oct 2010
    • 4

    #1

    How to output an array backward ?

    The question asking me to output backward, is it the same meaning as inverse output??

    this is what I've done so far :
    Code:
    /*Q3) Develop a C program that inputs a list of
    numbers, letting the user decide how many.
    Output the list backwards, but only output
    numbers greater than 20?*/
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    
        int i,N;
        int array[200];
    
        printf("Input The Size of the array you wish:\n");
        scanf("%d",&N);
        printf("Input the array of size %d:\n",N);
        for (i=0;i<N;i++)
        scanf("%d",&array[i]);
    
        printf("*****************\n");
        printf("The New array With backward order is:\n");
        for(i=N-1;i>=0;i--)
        if(array[i]>20)
        printf("%d\n",array[i]);
    
        return 0;
    }
    any suggestion ?
    Thanks
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Develop a C program that inputs a list of numbers, letting the user decide how many. Output the list backwards, but only output numbers greater than 20.
    My interpretation of these requirements is that your program must allow the user to enter any amount of numbers; then the program must print those same numbers back in reverse order (newest numbers first), being careful not to print any numbers less than or equal to 20.

    That is, if the user enters these numbers:
    • -10
    • 0
    • 10
    • 100
    • 20
    • 30
    • 40
    • 50


    The program must print:
    • 50
    • 40
    • 30
    • 100


    It looks to me like your program does this. Are you having any problems with it? By the way, you ought to verify that 'N' is not greater than 200 (the size of 'array').

    Comment

    • binarylife
      New Member
      • Oct 2010
      • 4

      #3
      My problem is that i need to know if they mean by backward the same as inverse order, but from your words I realized that it is the same.
      Also You are right that I should verify that "N" is not greater than 200.
      thanks A lot

      Comment

      Working...