#include <stdio.h>
#define MAX 100
int stack[MAX];
int top = -1;
// Push
void push(int x) {
stack[++top] = x;
}
// Pop
int pop() {
return stack[top--];
}
int main() {
int n, arr[MAX];
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter elements:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
push(arr[i]);
}
for (int i = 0; i < n; i++) {
arr[i] = pop();
}
printf("Reversed list: ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter