-->
当前位置:首页 > 题库

PROGRAMMING:5.5 - use macro to define the number of elements and arrange them in reverse order

Luz5年前 (2021-05-10)题库421
Modify the program in code listing 5-8 to define the number of elements with object macro instead. Note that you need to find rules about the number of element exchanges
-----Exercise 5-5 of "understanding C language"
```
/*
Listing 5-8: reverse the order of all the elements of the array
*/
#include
int main(void)
{
int i;
int x[7]; /* Int [7] array*/
for (i = 0; i < 7; i++) { /* Enter the value of the element*/
printf("x[%d] : ", i);
scanf("%d", &x[i]);
}
for (i = 0; i < 3; i++) { /* Array elements in reverse order*/
int temp = x[i];
x[i] = x[6 - i];
x[6 - i] = temp;
}
Put in reverse order;
for (i = 0; i < 7; i++) /* Displays the value of the element*/
printf("x[%d] = %d\n", i, x[i]);
return 0;
}
```
###Input example:
```in
fifteen
sixty-seven
twenty-eight
seventy-seven
thirty-five
ninety-one
eighty-three
```
###Output example:
The corresponding output is given here. For example:
```out
X [0]: x [1]: x [2]: x [3]: x [4]: x [5]: x [6]: in reverse order.
x[0] = 83
x[1] = 91
x[2] = 35
x[3] = 77
x[4] = 28
x[5] = 67
x[6] = 15
```







answer:If there is no answer, please comment