C/C++の宿題を片付けます 96代目
■ このスレッドは過去ログ倉庫に格納されています
0097デフォルトの名無しさん
2007/09/23(日) 15:06:32スタックの勉強でもしてるのかな?
#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;
}
■ このスレッドは過去ログ倉庫に格納されています