UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I write a C program for stack implementation using an array?

Asked by Last Modified  

Follow 2
Answer

Please enter your answer

Advance Excel And VBA Training

The C Program is written for implementation of STACK using Array, the basic operations of stack are PUSH(), POP() and DISPLAY(). PUSH function in the code is used to insert an element to the top of stack, POP function used to remove the element from the top of stack. Finally display function used to...
read more
The C Program is written for implementation of STACK using Array, the basic operations of stack are PUSH(), POP() and DISPLAY(). PUSH function in the code is used to insert an element to the top of stack, POP function used to remove the element from the top of stack. Finally display function used to print the values at any time. All stack functions are implemented in C Code. The same implementation of stack using c is written using pointers: Stack operations using pointers in c //stack using array #include "stdio.h" #include "conio.h" int stack[100],choice,n,top,x,i; void push(); void pop(); void display(); void main() { //clrscr(); top=-1; printf("\n Enter the size of STACK[MAX=100]:"); scanf("%d",&n); printf("\n\t STACK OPERATIONS USING ARRAY"); printf("\n\t--------------------------------"); printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT"); do { printf("\n Enter the Choice:"); scanf("%d",&choice); switch(choice) { case 1: { push(); break; } case 2: { pop(); break; } case 3: { display(); break; } case 4: { printf("\n\t EXIT POINT "); break; } default: { printf ("\n\t Please Enter a Valid Choice(1/2/3/4)"); } getch(); } } while(choice!=4); } void push() { if(top>=n-1) { printf("\n\tSTACK is over flow"); getch(); } else { printf(" Enter a value to be pushed:"); scanf("%d",&x); top++; stack[top]=x; } } void pop() { if(top<=-1) { printf("\n\t Stack is under flow"); } else { printf("\n\t The popped elements is %d",stack[top]); top--; } } void display() { if(top>=0) { printf("\n The elements in STACK \n"); for(i=top; i>=0; i--) printf("\n%d",stack[i]); printf("\n Press Next Choice"); } else { printf("\n The STACK is empty"); } } OUTPUT: Enter the size of STACK[MAX=100]:10 STACK OPERATIONS USING ARRAY -------------------------------- 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter the Choice:1 Enter a value to be pushed:12 Enter the Choice:1 Enter a value to be pushed:24 Enter the Choice:1 Enter a value to be pushed:98 Enter the Choice:3 The elements in STACK 98 24 12 Press Next Choice Enter the Choice:2 The popped elements is 98 Enter the Choice:3 The elements in STACK 24 12 Press Next Choice Enter the Choice:4 EXIT POINT read less
Comments

stack using push and pop opteration to implementation array
Comments

We will use 3 methods Push(): it is used for insterting data/element Pop():it is used to delete/remove data/element Display():used to display the stack
Comments

View 1 more Answers

Related Questions

How can you be sure that a program follows the ANSI C standard?
The ANSI C standard provides a predefined symbol named __STDC__ that is set to 1 when the compiler is enforcing strict ANSI standard conformance. If you want your programs to be 100 percent ANSI conformant,...
Vibha
Why do we use # in C programming?
In the C programming language, # is used for preprocessor directives. The preprocessor is a program that runs before the compiler and processes special directives that begin with # . These directives allow...
Dhanya
0 0
5
How do I become good in competitive programming in a year if I have just started learning C language?
The best topics to learn would be Data structures and also the analysis of algorithms..(THESE ARE BASICS BUT IF U LEARN THEM PROPERLY!!! CODING WOULD BE A PIECE OF CAKE FOR U....)
Anmol
0 0
9
Why is C programming language called C?
It was first known as New B as it was an improved version of the B programming language. As C comes next to B in the English alphabet, it was renamed C later before its release. C is the only programming...
Shiva
0 0
5
What is the meaning of \n and \t in C language?
is new line and \t is for tab
Priya
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

INTRODUCTION TO PROGRAMMING LANGUAGES
Language is a medium for communication. If we want to perform anything with another person, we can know the human language as a human being. Similarly, if we want to perform anything with a computer, we...

Array vs Linked List
Array Linked List Accessing element is easy. Accessing element is difficult compare to Array. Easy to use. Difficult to use. Memory is Fixed size. Memory is variable size. If...

C Program-Error Handling
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main function void main(){ int dividend=10; int divisor=0; int quotient; //Function for clearing screen clrscr(); ...
S

Working with C/C++ applications
Inorder to learn C and C++ programming languages one can work with various editors available.To name a few are the most popular one is turbo c++, DEV C++, Eclipse, NetBeans. Here are the screen shots...
S

Can we store different data types in a stack?
Yesterday, one of my Facebook friend asked me this question. My answer is "yes", and in this post I will discuss how could we do this.I am a great supporter of working with unions and I will be using union...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more