how to print an array backwards

后端 未结 6 1493
太阳男子
太阳男子 2021-01-17 09:20

The user enteres a number which is put in an array and then the array needs to be orinted backwadrds

int main()
{
    int numbers[5];
    int x;

    for (i         


        
6条回答
  •  遇见更好的自我
    2021-01-17 09:35

    this one is more simple

    #include
    
    using namespace std;
    
    int main ()
    
    {
    
    int a[10], x, i;
    
    cout << "enter the size of array" << endl;
    
    cin >> x;
      cout << "enter the element of array" << endl;
    
    for (i = 0; i < x; i++)
        {
    
    cin >> a[i];
    
    }
    
    cout << "reverse of array" << endl;
    
    for (i = x - 1; i >= 0; i--)
    
    cout << a[i] << endl;
    
    }
    

提交回复
热议问题