Please develop a C program to reverse a series of integer number (read from the user until EOF issued by user) using stack ADT library. Please include c code and three sample run demonstrations with at least 10 different numbers each time.

Respuesta :

Answer:

#include <stdio.h>

#define MAX_CH 256

int main(void) {

int ch, i, length;

char string[MAX_CH];

for (;;) {

for (i = 0; i < MAX_CH; i++) {

if ((ch = getchar()) == EOF || (ch == '\n')) break; string[i] = ch; }

length = i;

if (length == 0) { break; }

for (i = 0; i < length; i++) { putchar(string[length - i - 1]); }

putchar('\n');

}

return 0;

}

Explanation:

  • Take input from user until the end of file.
  • Reverse the string using the following technique:
  • putchar(string[length - i - 1])