07/09/23 15:06:32
>>92
スタックの勉強でもしてるのかな?
#include <stdio.h>
#define S_MAX 500
int stack[S_MAX];
int top=-1;
void push(int x){
stack[++top] = x;
}
int pop(){
return stack[top--];
}
int main(){
int i=1;
while(i!=0){
printf("非負値の入力(0で終了):");
scanf("%d", &i);
if(i<0){
printf("非負値じゃないとダメです\n");
}else if(i!=0){
push(i);
}
}
printf("--- 結果 ---\n");
while(top!=-1){
printf("%d\n", pop());
}
return 0;
}