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

Where is C used today?
C programming language is still widely used today in various domains. Here are some areas where C remains prevalent: System Programming: C is extensively used for developing operating systems and...
S
0 0
6
What are all the data types in C programming with their details?
In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations...
Ganga
0 0
6
What are the control statements in C language?
The if statement, for loop, while loop, switch statement, break statement, and continue statement are C's most widely used control statements.
Jitender
0 0
6
what is syntex error
In computer science, a syntax error ( not Syntex ) is an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language. For compiled languages,...
Tanha

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

Ask a Question

Related Lessons

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

All About Programming And A Good Programmer.
Hi, This is my first lesson for you guys. Hope you enjoy reading it. In recent community questions, I found many people wanted to be good programmers, or wanted to have good hands on certain language,...

Some interview questions and answers for fresher level on Pointers
What is a void pointer? Void pointer is a special type of pointer which can reference or point to any data type. This is why it is also called as Generic Pointer. As a void pointer can point to...

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

C Program to print Block Letter and Small Case Alphabets using C
/* WAP to print Block Letter and Small Case Alpahbets using C*/ //Hint:use ascii code(value) to print #include#include void main(){ int i; clrscr(); //Block Letters Alphabets printf("Block Letters Alphabets\n");...
S

Recommended Articles

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 >

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 >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

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