Write a c program to read 4 numbers and then print them in r

Write a c program to read 4 numbers and then print them in reverse order. Use a symbolic constant to declare and process the array.

Example:
enter value for array element [0]: 5

enter value for array element [1]:4.55
enter value for array element [2]:10
enter value for array element [3]:25.2

myArray: 5 4.55 10 25.2

myArray(reversed): 25.2 10 4.55 5

Solution

// C++ code to reverse array

#include <iostream>
#include <fstream>
#include <string.h>
#define SIZE 4
using namespace std;

int main()
{   
double array[SIZE];

for (int i = 0; i < SIZE; ++i)
{
cout << \"enter value for array element [\" << i << \"]: \";
cin >> array[i];
}

cout << \"\ \ myArray: \";
for (int i = 0; i < SIZE; ++i)
{
cout << array[i] << \" \";
}


// reversing array
for (int i = 0; i < SIZE/2; ++i)
{
double temp = array[i];
array[i] = array[SIZE-i-1];
array[SIZE-i-1] = temp;
}

cout << \"\ myArray(reversed):: \";
for (int i = 0; i < SIZE; ++i)
{
cout << array[i] << \" \";
}

cout << endl;

return 0;
}

/*
output:

enter value for array element [0]: 5
enter value for array element [1]: 4.55
enter value for array element [2]: 10
enter value for array element [3]: 25.2


myArray: 5 4.55 10 25.2
myArray(reversed):: 25.2 10 4.55 5

*/

Write a c program to read 4 numbers and then print them in reverse order. Use a symbolic constant to declare and process the array. Example: enter value for arr
Write a c program to read 4 numbers and then print them in reverse order. Use a symbolic constant to declare and process the array. Example: enter value for arr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site