Ich habe versucht, Stack-Betrieb zu implementieren und während der Push-Operation ist der eingegebene Wert immer 0. Wenn ich eine beliebige Zahl eingeben, ist das Ergebnis in das geladene Array immer 0.Fehler im Stack Betrieb an einem Array im Push-Betrieb
//Stack Operation
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int stack[10];
int top=0;
void push()
{
int i;
printf("Enter the element you want to add");
scanf("%d",& stack[top]);
top++;
printf("%d",stack[top]);
printf("The element is added\n");
for(i=0;i<top;i++) {
printf("%d",stack[top]);
}
}
int pop()
{
top--;
return(stack[top]);
}
void display()
{
int i;
for(i=0;i<=top;i++);
{
printf("%d \t",stack[i]);
}
}
void main()
{
int ch;
clrscr();
label:
printf("1---->Push\n");
printf("2---->Pop\n");
printf("3----->Display\n");
printf("4-----> Exit\n");
printf("Enter your choice");
scanf("%d",&ch);
if(ch==1) {
clrscr();
push();
goto label;
}
if(ch==2) {
int f;
clrscr();
f=pop();
printf("Poped Element %d",f);
goto label;
}
if(ch==3) {
clrscr();
display();
goto label;
}
if(ch==4) {
exit(0);
}
getch();
}
Sind Sie sicher, dass Sie die Erhöhung zwischen 'scanf ("% d ", & stack [top]) wünschen; top ++; printf ("% d", stack [top]); ' –
Ich glaube, ich habe meinen Fehler. –