Wednesday, 6 August 2014

Please help me to debug this program

#include<stdio.h>
#include<conio.h>
#define MAX 10
int stack[MAX];
int top=-1;
void push(int);
void display();
 void main()
{
    int num;
    printf{"enter a number"};
    scanf("%d",&num);
    push(num);
}
void push(int element)
{
     if top==max-1
     {
                  printf("state overflow\n");
                  return;
                  }
                  else
                  {
                  top=top+1;
                  stack[top]=element;
                  }
                  }
                 

5 comments:

  1. i try to debug it like
    #include
    #include
    #define MAX 10
    int stack[MAX];
    int top=-1;
    void push(int);
    void display();
    main()
    {
    int num;
    printf("enter a number");
    scanf("%d",&num);
    push(num);
    }
    void push(int element)
    {
    if (top == MAX-1)
    {
    printf("state overflow\n");
    return;
    }
    else
    {
    top=top+1;
    stack[top]=element;
    }
    }

    ReplyDelete
  2. Give a heading about which the program is, so that users can debug it and increase its readability.

    ReplyDelete
  3. sorry for that and this programme is about push function in stack using array

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Its a C programming,
    1. header file is missing,
    2. void datatype is not valid is C, its supporting as the compiler is supporting C and C++ both.
    3. display() function is not defined, its only declared,
    4. If we run the program, after entering any number, its terminated.
    Try to debug it properly again.

    ReplyDelete

Note: only a member of this blog may post a comment.