SlideShare a Scribd company logo
1)‘C’ Program
/************************************************************
Program for implementing a stack using arrays.It involves
various operations such as push,pop,stack empty,stack full and
display.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
/* stack structure*/
struct stack {
               int s[size];
               int top;
            }st;
/*
  The stfull Function
  Input:none
  Output:returns 1 or 0 for stack full or not
  Called By:main
  Calls:none
*/
int stfull()
{
  if(st.top>=size-1)
return 1;
  else
   return 0;
}
/*
  The push Function
  Input:item which is to be pushed
  Output:none-simply pushes the item onto the stck
  Called By:main
  Calls:none
*/
void push(int item)
{
  st.top++;
  st.s[st.top] =item;
}
/*
  The stempty Function
  Input:none
  Output:returns 1 or 0 for stack empty or not
  Called By:main
  Calls:none
*/
int stempty()
{
  if(st.top==-1)
   return 1;
  else
   return 0;
}
/*
  The pop Function
  Input:none
  Output:returns the item which is popped from the stack
  Called By:main
  Calls:none
*/
int pop()
{
  int item;
  item=st.s[st.top];
  st.top – –;
  return(item);
}
/*
  The display Function
  Input:none
  Output:none-displys the contents of the stack
  Called By:main
  Calls:none
*/
void display()
{
  int i;
  if(stempty())
     printf(―n Stack Is Empty!‖);
  else
  {
    for(i=st.top;i>=0;i– –)
    printf(―n%d‖,st.s[i]);
  }
}
/*
  The main Function
  Input:none
  Output:none
  Called By:O.S.
  Calls:push,pop,stempty,stfull,display
*/
void main(void)
{
int item,choice;
char ans;
st.top=-1;
clrscr();
printf(―ntt Implementation Of Stack‖);
do
{
  printf(―n Main Menu‖);
  printf(―n1.Pushn2.Popn3.Displayn4.exit‖);
  printf(―n Enter Your Choice‖);
  scanf(―%d‖,&choice);
  switch(choice)
{
     case 1:printf(―n Enter The item to be pushed‖);
                 scanf(―%d‖,&item);
                 if(stfull())
                  printf(―n Stack is Full!‖);
                 else
                  push(item);
                break;
     case 2:if(stempty())
                printf(―n Empty stack!Underflow !!‖);
            else
          {
             item=pop();
             printf(―n The popped element is %d‖,item);
          }
          break;
     case 3:display();
                    break;
     case 4:exit(0);
  }
  printf(―n Do You want To Continue?‖);
  ans=getche();
  }while(ans ==‘Y‘ ||ans ==‘y‘);
getch();
}
/******************** End Of Program ************************/
2)‘C’ Program
/************************************************************
Program to evaluate a given postfix expression. The program
handles postfix expressions with only binary arithmatic
operators +,-,*,/ and ^. Operands are single digit numbers
between 0-9.
*************************************************************/
/* List of include files */
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
/* List of defined constants */
#define size 80
/* Global declarations */
struct stack
{         double   s[size];
            int top;
}st;
enum Type { operand, oprtor };
/*      The Push function
        Input : A value to be pushed on global stack
        Output: None, modifies global stack and its top
    Parameter Passing Method :By Value
            Called By : Post()
Calls :none
*/
void Push(double Val)
{
      if ( st.top+1 >= size )
           printf(―Error: Stack is Fulln‖);
      st.top++;
      st.s[st.top] = Val;
}
/*    The Pop function
      Input : None, uses global stack and top
      Output: Returns the value on top of stack
      Parameter Passing Method :None
      Called By : post()
      Calls :none
*/
double Pop()
{
      double Val;
      if ( st.top == -1 )
           printf(―Error: Stack is Emptyn‖);
      Val = st.s[st.top];
      st.top—;
      return(Val);
}
/*    The gettokn function
      Input : Given infix expression
      Output: Returns the next character from the expression
      Parameter Passing Method : By reference
      Called By : post()
      Calls : None
*/
char gettokn( char exp[])
{
      static int i = 0;
      char ch;
      ch = exp[i];
      i++;
      return ch;
}
/*    The Gettype function
      Input : A character from infix expression
      Output: Returns the token type as operand or oprtor
      Parameter Passing Method : By value
      Called by : post()
Calls : none
*/
enum Type Gettype(char ch)
{
      ch = toupper(ch); /* convert to upper case */
      if ( ch >= ‗0‘ && ch <= ‗9‘)
           return operand;
      if ( ch == ‗+‘|| ch == ‗-‘||
            ch == ‗*‘|| ch == ‗/‘ ||
ch == ‗^‘ )
             return oprtor;
        /* Error */
     printf(―Invalid operatorn‖);
}
/*     The post function which contains major logic of
       the program.
       Input : A post Expression of single digit operand
       Output: Resultant value after evaluating the expression
       Parameter Passing Method :by reference
       Called By : main()
       Calls :gettoken(), Push(), Pop() and
              Gettype()
*/
double post( char exp[])
{
      char    ch,type;
      double result, Val, Op1, Op2;
      st.top = 0;
      ch = gettokn(exp);
      while ( ch != ‗$‘ )
      {
           type = Gettype(ch);
           if( type ==operand)
           {
                Val = ch - 48;
                Push( Val);
           }
           else
           if ( type == oprtor)
           {
                 Op2 = Pop();
                 Op1 = Pop();
                 switch(ch)
           {
                case ‗+‘ : result = OP1 + Op2;
                                 break;
                case ‗–‘ : result = Op1 – Op2;
                                 break;
                case ‗*‘ : result = Op1 * Op2;
                                 break;
                case ‗/‘ : result = Op1 / Op2;
                                 break;
                case ‗^‘ : result = pow (Op1 – Op2;
                                 break;
                }/* switch */
                Push (result);
           }
           ch = gettokn(exp);
      }/* while */
      result = Pop();
      return(result);
}
/*    The main function
Input : None
         Output : None
         Parameter Passing Method : None
         called By : OS
         Calls : post()
    */
    void main ()
    {
            /* Local declarations */
            char     exp[size];
            int      len;
            double   Result;
            clrscr();
            printf(―‖Enter the postfix Expressionn");
            scanf(―%S‖,exp);
            len = strlen(exp);
            exp[len] = ‗‘; /* Append at the end */
            Result = post(exp);
            printf(―The Value of the expression is %fn‖, Result);
            getch();
            exit(0);
    }
    / ************** End of the Program ***************** /
3) ‘C’ Program
/ **********************************************************
Program for conversion of Infix expression to Postfix form.
************************************************************/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
char inf[40],post[40];
int top=0,st[20];
void postfix();
void push(int);
char pop();
/*
The main Function
Input:none
Output:none
Called BY:O.S.
Calls:postfix
*/
void main(void)
{
         clrscr();
         printf(―ntEnter the infix expression :: nntt‖);
         scanf(―%s‖, inf);
         postfix();
         getch();
}
/*
The postfix Function
Input:none
Output:none
Called By:main
Calls:push,pop
*/
void postfix()
{
int i,j=0;
for(i=0;inf[i]!=‘0‘;i++)
{
switch(inf[i])
{
case ‗+‘ : while(st[top] > = 1)
                   post[j++] = pop();
             push(1)
             break;
case ‗–‘ : while(st[top] >=1)
                   post[j++] = pop();
             push(2);
             break;
case ‗*‘ : while(st[top] >=3)
                   pos[j++] = pop();
             push(3)
             break;
case ‗/‘ : while(st[top] > = 3)
                   post[j++] = pop();
             push(4);
             break;
case ‗^‘ : while(st[top] >=4)
                   post[j++] = pop();
              push(5);
              break;
    case ‗(‗ : push(0);
              break;
    case ‗)‘ : while(st[top] ! = 0
                   post[j++] = pop();
              top —;
              break;
    default : post[j++] = inf[i];
    }
    }
while(top>0)
post[j++] = pop();
print(―ntPostfix expression is = > nntt %s‖, post);
}
/*
  The push Function
  Input:ele-the element which is to be pushed onto the stack
  Output:none
  Called By:postfix
  Calls:none
*/
void push(int ele)
{
top++;
st[top] = ele;
}
/*
  The pop Function
  Input:none
  Output:e-the popped element
  Called By:postfix
  Calls:none
*/
char pop()
  {
       int el;
       char e;
       el = st[top];
       top—;
       switch(el)
       {
         case 1 : e = ‗+‘;
              break;
         case 2 : e = ‗–‘;
              break;
         case 3 : e = ‗*‘;
              break;
         case 4 : e = ‗/‘;
              break;
         case 5 : e = ‗^‘;
              break;
       }
       return(e);
}
/**************** end of program ********************/
4)C Program
/************************************************************
      Program for checking the well formedness of the parenthesis.
    *************************************************************/
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #define size 5

  /* stack structure*/
  struct stack {
              char s[size];
              int top;
             }st;

  /*
    The push Function
    Input:item which is to be pushed
    Output:none-simply pushes the item onto the stck
    Called By:main
    Calls:none
  */
  void push(char item)
  {
st.top++;
 st.s[st.top] =item;
}
/*
  The stempty Function
  Input:none
  Output:returns 1 or 0 for stack empty or not
  Called By:main
  Calls:none
*/
int stempty()
{
  if(st.top==-1)
    return 1;
  else
    return 0;
}
/*
  The pop Function
  Input:none
  Output:returns the item which is popped from the stack
  Called By:main
  Calls:none
*/
char pop()
{
  char item;
  item=st.s[st.top];
  st.top—;
  return(item);
}
/*
  The main Function
  Input:none
  Output:none
  Called By:O.S.
  Calls:push,pop,stempty
*/
void main(void)
{
  char item;
  char ans,bracket[10];
  int i;
  st.top=-1;
  clrscr();
  printf(―ntt Enter The expression and put $ at the end‖);
  scanf(―%s‖,bracket);
  i=0;
  if(bracket[i]==‘)‘)
    printf(―n The expression is invalid‖);
  else
  {
     do
     {
while(bracket[i]==‘(‗)
        {
          push(bracket[i]);
          i++;
        }
        while(bracket[i]==‘)‘)
        {
           item=pop();
           i++;
        }
   }while(bracket[i]!=‘$‘);
   if(!stempty())
     printf(―n The expression is invalid‖);
   else
     printf(―n The expression has well formed parenthesis‖);
   }
   getch();
   }
5)C Program
/*************************************************************
     Program for converting decimal number to binary number
   *************************************************************/
   #include<stdio.h>
   #include<conio.h>
   #include<stdlib.h>
   #define size 5

  /* stack structure*/
  struct stack {
              int s[size];
              int top;
             }st;

  /*
    The push Function
    Input:item which is to be pushed
    Output:none-simply pushes the item onto the stck
    Called By:main
    Calls:none
  */
  void push(int item)
  {
    st.top++;
    st.s[st.top] =item;
  }
  /*
    The stempty Function
    Input:none
    Output:returns 1 or 0 for stack empty or not
    Called By:main
    Calls:none
  */
  int stempty()
  {
if(st.top==-1)
    return 1;
   else
    return 0;
   }
   /*
     The pop Function
     Input:none
     Output:returns the item which is popped from the stack
     Called By:main
     Calls:none
   */
   int pop()
   {
     int item;
     item=st.s[st.top];
     st.top—;
     return(item);
   }
   /*
     The main Function
     Input:none
     Output:none
     Called By:O.S.
     Calls:push,pop,stempty
   */
   void main(void)
   {
     int item,i,num;
     st.top=-1;
     clrscr();
     printf(―n Program For Decimal TO Binary Conversion‖);
     printf(―ntt Enter The number‖);
     scanf(―%d‖,&num);
     while(num>=1)
       {
        item=num%2;
        push(item);
        num=num/2
       }
     while(!stempty())
     printf("%d",pop());
     getch();
     }
 6)C Program
/*************************************************************
  Program for reversing the given string using stack
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define size 10
/* stack structure*/
struct stack {
             char s[size];
             int top;
            }st;

/*
  The push Function
  Input:item which is to be pushed
  Output:none-simply pushes the item onto the stck
  Called By:main
  Calls:none
*/
void push(char item)
{
  st.top++;
  st.s[st.top] =item;
}
/*
  The stempty Function
  Input:none
  Output:returns 1 or 0 for stack empty or not
  Called By:main
  Calls:none
*/
int stempty()
{
  if(st.top==-1)
   return 1;
  else
   return 0;
}
/*
  The pop Function
  Input:none
  Output:returns the item which is popped from the stack
  Called By:main
  Calls:none
*/
char pop()
{
  char item;
  item=st.s[st.top];
  st.top—;
  return(item);
}
/*
  The main Function
  Input:none
  Output:none
  Called By:O.S.
  Calls:push,pop,stempty
*/
void main(void)
{
  char item,string[10];
  int i;
  st.top=-1;
  clrscr();
  printf(―n Program For reversing a given string‖);
  printf(―ntt Enter The string:‖);
  scanf(―%s‖,&string);
  i=0;
  while(string[i]!=‘0‘)
    {
     push(string[i]);
     i++;
    }
printf(―ttt‖);
  while(!stempty())
  {
    item=pop();
    printf(―%c‖,item);
  }
  getch();
}

7)‘C’ Program
/*************************************************************
Program to implement multiple stacks using single array
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 20
int stack[MAX];
int size[MAX],lb,ub;
/* set_stack Function
  It is for defining the upper limit and lower limit of each stack
  Input:the index,which indicates the stack number
  Output:none,It sets the upper and lower boundries of the stack
  Called By:stempty,stfull,display,display_all
  Calls:none
  Parameter passing method:By value
*/
void set_stack(int index)
{
  int sum,i;
  if(index==1)
  {
    lb=1;
    ub=size[index];
  }
  else
  {
    sum=0;
    for(i=1;i<index;i++)
     sum=sum+size[i];
lb=sum+1;
  ub=sum+size[index];
  }
}
/* stfull Function
It checks whether the stack is full or not
  Input:the index,which indicates the stack number
  Output:1 if stack is full otherwise 0
  Called By:main
  Calls:set_stack
  Parameter passing method:By value
*/
int stfull(int index)
{
  int top,i,sum;
  set_stack(index);
  for(top=lb;top<=ub;top++)
  {
     if(stack[top]==-1)
        break;
    }
    if(top-1==ub)
     return 1;
    else
     return 0;
}
/* stempty Function
It checks whether the stack is empty or not
  Input:the index,which indicates the stack number
  Output:1 if stack is empty otherwise 0
  Called By:main
  Calls:set_stack
  Parameter passing method:By value
*/
int stempty(int index)
{
  int top;
  set_stack(index);
  for(top=lb;top<=ub;top++)
    {
     if(stack[top]!=-1)
        return 0;
     return 1;
    }
}
/* push Function
  Input:the item which is to be pushed onto the stack
  Output:none
  Called By:main
  Calls:
  Parameter passing method:By value
*/
void push(int item)
{
int top;
 for(top=lb;top<=ub;top++)
  if(stack[top]==-1)
   break;
  stack[top]=item;
 return;
}
/* pop Function
It pops the element from desired stack
  Input:none
  Output:item,popped element
  Called By:main
  Calls:none
*/
int pop()
{
    int top,item;;
    for(top=lb;top<=ub;top++)
     if(stack[top]==-1)
     break;
     top—;
     item=stack[top];
     stack[top]=-1;
     return item;
}
/* display Function
  It displays only desired stack
  Input:the index,which indicates the stack number
  Output:none
  Called By: main
  Calls:set_stack
  Parameter passing method:By value
*/
void display(int index)
{
    int top;
    set_stack(index);
  for(top=lb;top<=ub;top++)
  {
    if(stack[top]!=-1)
     printf(―%d‖,stack[top]);
  }
}

/* display_all Function
  It displays all the stacks in the array
  Input:the n,which indicates total number of stacks
  Output:none
  Called By:main
  Calls:set_stack
  Parameter passing method:By value
*/void display_all(int n)
{
  int top,index;
for(index=1;index<=n;index++)
 {
   printf(―nstack number %d is‖,index);
   set_stack(index);
   for(top=lb;top<=ub;top++)
   {
   if(stack[top]!=-1)
    printf(― %d‖,stack[top]);
   }
 }
}
/* main Function
  Input:none
  Output:none
  Called By:O.S.
  Calls:stfull,push,stempty,pop,display,display_all
  Parameter passing method:
*/
void main(void)
{
  int n,index,i,item,choice;
  char ans;
  clrscr();
  ans=‘y‘;
  for(i=1;i<=MAX;i++)
    stack[i]=-1;/*for initialization of the entire array of stacks*/
  printf(―nt Program For multiple stacks using single array‖);
  printf(―n Enter how many stacks are there‖);
  scanf(―%d‖,&n);
  printf(―n Enter the size for each stack‖);
  for(i=1;i<=n;i++)
  {
     printf(―n size for stack %d is‖,i);
     scanf(― %d‖,&size[i]);
  }
  do
    {
    printf(―ntt Main Menu‖);
    printf(―n 1.Push n2.Pop n3.Display n4.Dispaly all‖);
    printf(―n Enter Your choice‖);
    scanf(―%d‖,&choice);
    switch(choice)
    {
     case 1:printf(―n Enter the item to be pushed‖);
               scanf(―%d‖,&item);
               printf(―n In Which stack?‖);
               scanf(―%d‖,&index);
               if(stfull(index))
                printf(―n Stack %d is Full,can not Push‖,index);
               else
                push(item);
               break;
     case 2:printf(―n From Which stack?‖);
               scanf(―%d‖,&index);
if(stempty(index))
               printf(―n Stack number %d is empty!‖,index);
             else
               {
                  item=pop();
                  printf(―n %d is popped from stack %d‖,item,index);
               }
             break;
   case 3:printf(―n Which stack has to be displayed?‖);
             scanf(―%d‖,&index);
             display(index);
             break;
   case 4:display_all(n);
             break;
   default:printf(―n Exitting‖);
  }
  printf(―n Do you wish to continue?‖);
  ans=getch();
  }while(ans==‘y‘||ans==‘Y‘);
  getch();
 }
/********************* End Of Program**********************/
8)C Program

/*******************************************************************************************
Program for finding out the factorial for any given number.
*************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
/* The fact function
Input:the numer n
Output: factorial of n
Called By:main
Calls:itself
*/
int fact(int n)
{
  int x,y;
  if(n<0)
  {
    printf(―The negative parameter in the factorial function‖);
    exit(0);
    }
    if(n==0)
    return 1;
    x=n-1;
    y=fact(x);
    return(n*y);
  }
/* The main function
Input:none
Output:none
Called By:O.S.
Calls:fact
*/
void main(void)
  {
    int n,f;
    clrscr();
    printf(―ntt Program For finding the factorial of n‖);
    printf(―nn Enter the number for finding the factorial‖);
    scanf(―%d‖,&n);
    f=fact(n);
    printf(―n the factorial of %d is %d‖,n,f);
    getch();
  }
/********************** End Of Program **********************/
9)C Program
/*************************************************************
Program for computing the number in the fibonacci series at
certain location.For e.g.the sixth number in fibonacci series
will be 8.The fibonacci series is 1 1 2 3 5 8 13 21 34...
*************************************************************/
/*header files*/
#include<stdio.h>
#include<conio.h>
/*
  The fib Function.
  Input:the location n.
  Output:the value at that location in fibonacci series.
  Called By:main.
  Calls:itself.
*/
int fib(int n)
{
  int x,y;
  if(n<=1)
    return n;
  x=fib(n-1);
  y=fib(n-2);
    return (x+y);
}
/*
  The main function
  Input:none
  Output:none
  Called By:o.s
  Calls:fib-the fibonacci function.
*/
void main(void)
{
  int n,num;
  clrscr();
  printf(―n Enter location in fibonacci series‖);
  scanf(―%d‖,&n);
  num=fib(n);
  printf(―n The number at %dth position is %d in fibonacci
series‖,n,num);
 getch();
}
/********************** End of Program ***********************/
10)C Program
/*************************************************************
Program for Multiplication Of natural numbers.The multiplication
two numbers is considerd.This is program uses the recurssive
definition.
*************************************************************/
/*header files*/
#include<stdio.h>
#include<conio.h>
/*************************************************************
mul Function
Input:two numbers a,b
Output:returns the multiplication result
Called by:main
Calls:mul i.e.itself
*************************************************************/
mul(int a,int b)
{
    if(b==1)
    return a;
    else
     return(mul(a,b-1)+ a);
}
/*************************************************************
main Function
Input:none
Output:none
Called by:O.S.
Calls:mul
*************************************************************/
main()
{
    int a,b,result=0;
    clrscr();
    printf(―n Enter the values of a and b‖);
    scanf(―%d%d‖,&a,&b);
    result=mul(a,b);
    printf(―The multiplication is =%d‖,result);
    getch();
  }
11)C Program
/*************************************************************
Program to find out the greatest common divisor of the two
integers.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int gcd(int a,int b)
{
int temp,ans;
 if(b<=a &&a%b ==0)
   return b;
 else
 {
   if(b<a)
   {
    temp = a;
    a = b;          /*interchanging the a and b values*/
    b = temp;
   }
   ans = a%b;
   return(gcd(b,ans));
 }
}
void main(void)
{
  int a,b,ans;
  clrscr();
  printf(―ntt GCD Of two integers‖);
  printf(―nn Enter the two numbers‖);
  scanf(―%d %d‖,&a,&b);
  ans=gcd(a,b);
  printf(―n The gcd of %d and %d is = %d‖,a,b,ans);
  getch();
}
/********************** End of program *******************/
12)C Program
/*******************************************************************
Conversion of postfix expression to infix form
*******************************************************************/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>

typedef struct node
{
  char str[25];
}node;

node stack[20];
int top = –1;
char input[100];
void post2in();

void push(char *op)
{
  if(top == 20)
  {
       printf("nStack full");
       exit(0);
  }
  top++;
strcpy(stack[top].str,op);
}

char *pop()
{
  char *op;
  op=(char *)malloc(25);
  if(top==–1)
  {
       printf("ntlllegal expression : operand missing");
       exit(0);
  }
  strcpy(op,stack[top].str);
  top--;
  return(op);
}

void main()
{
  clrscr();
  printf("ntt Program for postfix to infix conversion");
  printf("ntEnter postfix expression ::nntt);
  scanf("%s",input);
  post2in();
  getch();
}

void post2in()
{
  char*op1,*op2,op[25];
  int i=0;

 while(input[i]!='0')
 {
      if(input[i]!='+'&& input[i]!='–'&& input[i]!='*'&&
      input[i]!='/')
      {
            op[0]=input[i];
            op[1]='0';
            push(op);
      }
      else
      {
            op2=pop();
            op1=pop();
            sprintf(op,"(%s%c%s)",op1,input[i],op2);
            free(op1);
            free(op2);
            push(op);
      }
      i++;
 }
 if(top==0)
 {
print("ntinfix expression is::nntt%s",
                stack[0].str);
 }
 else
 {
        print("ntlllegal input expression:operator
                missingn");
  }
}
13)C Program
/*******************************************************************
Conversion of postfix expression to prefix form
*******************************************************************/

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>

typedef struct node
{
  char str[25];
}node;

node stack[20];
int top = –1;
char input[100];
void post2pre();

void push(char *op)
{
  if(top == 20)
  {
       printf("nStack full");
       exit(0);
  }
  top++;
strcpy(stack[top].str,op);
}

char *pop()
{
  char *op;
  op=(char *)malloc(25);
  if(top==–1)
  {
       printf("ntlllegal expression : operand missing");
       exit(0);
  }
  strcpy(op,stack[top].str);
  top--;
  return(op);
}
void main()
{
  clrscr();
  printf("ntt Program for postfix to prefix form");
  printf("ntEnter postfix expression ::nntt);
  scanf("%s",input);
  post2pre();
  getch();
}

void post2pre()
{
  char*op1,*op2,op[25];
  int i=0;

    while(input[i]!='0')
    {
         if(input[i]!='+'&& input[i]!='–'&& input[i]!='*'&&
         input[i]!='/')
         {
               op[0]=input[i];
               op[1]='0';
               push(op);
         }
         else
         {
               op2=pop();
               op1=pop();
               sprintf(op,"(%c%s%s)",input[i],op1,op2);
               free(op1);
               free(op2);
               push(op);
         }
         i++;
    }
    if(top==0)
    {
         print("ntPrefix expression is::nntt%s",
                 stack[0].str);
    }
    else
    {
         print("ntlllegal input expression:operator
                 missingn");
    }
}

More Related Content

What's hot

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
iCreateWorld
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
Munazza-Mah-Jabeen
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Mohammad Imam Hossain
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
Sayantan Sur
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
Sukrit Gupta
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
varadasuren
 
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in PythonCodemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Yothin Muangsommuk
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
Prabhu Govind
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
Rajendran
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
Naveen Kumar
 
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’aTen Typ tak ma - O systemach typów na przykładzie TypeScript’a
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
Artur Skowroński
 
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
Mahmoud Samir Fayed
 
3. control statement
3. control statement3. control statement
3. control statement
Shankar Gangaju
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 

What's hot (20)

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in PythonCodemania101: The Present, Past and Future of Asynchronous Programming in Python
Codemania101: The Present, Past and Future of Asynchronous Programming in Python
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
 
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’aTen Typ tak ma - O systemach typów na przykładzie TypeScript’a
Ten Typ tak ma - O systemach typów na przykładzie TypeScript’a
 
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
 
3. control statement
3. control statement3. control statement
3. control statement
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 

Similar to Stack prgs

Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
Ismar Silveira
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Er. Ganesh Ram Suwal
 
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptxData Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
RashidFaridChishti
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
armyshoes
 
STACK1.docx
STACK1.docxSTACK1.docx
STACK1.docx
CharanKeasavan
 
About Go
About GoAbout Go
About Go
Jongmin Kim
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
Sheikh Monirul Hasan
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
MeghaKulkarni27
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
aptcomputerzone
 
#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx
ajoy21
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf
asif1401
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 

Similar to Stack prgs (20)

week-18x
week-18xweek-18x
week-18x
 
week-17x
week-17xweek-17x
week-17x
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptxData Structures and Agorithm: DS 08 Infix to Postfix.pptx
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
week-16x
week-16xweek-16x
week-16x
 
STACK1.docx
STACK1.docxSTACK1.docx
STACK1.docx
 
About Go
About GoAbout Go
About Go
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 

More from Ssankett Negi

Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsortSsankett Negi
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
Ssankett Negi
 
Recursion
RecursionRecursion
Recursion
Ssankett Negi
 
Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
Ssankett Negi
 

More from Ssankett Negi (9)

Binary tree
Binary treeBinary tree
Binary tree
 
Multi way&btree
Multi way&btreeMulti way&btree
Multi way&btree
 
Heapsort
HeapsortHeapsort
Heapsort
 
Binary trees
Binary treesBinary trees
Binary trees
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Recursion
RecursionRecursion
Recursion
 
Circular queues
Circular queuesCircular queues
Circular queues
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 

Recently uploaded

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Stack prgs

  • 1. 1)‘C’ Program /************************************************************ Program for implementing a stack using arrays.It involves various operations such as push,pop,stack empty,stack full and display. *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 /* stack structure*/ struct stack { int s[size]; int top; }st; /* The stfull Function Input:none Output:returns 1 or 0 for stack full or not Called By:main Calls:none */ int stfull() { if(st.top>=size-1) return 1; else return 0; } /* The push Function Input:item which is to be pushed Output:none-simply pushes the item onto the stck Called By:main Calls:none */ void push(int item) { st.top++; st.s[st.top] =item; } /* The stempty Function Input:none Output:returns 1 or 0 for stack empty or not Called By:main Calls:none */ int stempty() { if(st.top==-1) return 1; else return 0;
  • 2. } /* The pop Function Input:none Output:returns the item which is popped from the stack Called By:main Calls:none */ int pop() { int item; item=st.s[st.top]; st.top – –; return(item); } /* The display Function Input:none Output:none-displys the contents of the stack Called By:main Calls:none */ void display() { int i; if(stempty()) printf(―n Stack Is Empty!‖); else { for(i=st.top;i>=0;i– –) printf(―n%d‖,st.s[i]); } } /* The main Function Input:none Output:none Called By:O.S. Calls:push,pop,stempty,stfull,display */ void main(void) { int item,choice; char ans; st.top=-1; clrscr(); printf(―ntt Implementation Of Stack‖); do { printf(―n Main Menu‖); printf(―n1.Pushn2.Popn3.Displayn4.exit‖); printf(―n Enter Your Choice‖); scanf(―%d‖,&choice); switch(choice)
  • 3. { case 1:printf(―n Enter The item to be pushed‖); scanf(―%d‖,&item); if(stfull()) printf(―n Stack is Full!‖); else push(item); break; case 2:if(stempty()) printf(―n Empty stack!Underflow !!‖); else { item=pop(); printf(―n The popped element is %d‖,item); } break; case 3:display(); break; case 4:exit(0); } printf(―n Do You want To Continue?‖); ans=getche(); }while(ans ==‘Y‘ ||ans ==‘y‘); getch(); } /******************** End Of Program ************************/ 2)‘C’ Program /************************************************************ Program to evaluate a given postfix expression. The program handles postfix expressions with only binary arithmatic operators +,-,*,/ and ^. Operands are single digit numbers between 0-9. *************************************************************/ /* List of include files */ #include <stdio.h> #include <conio.h> #include <process.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <math.h> /* List of defined constants */ #define size 80 /* Global declarations */ struct stack { double s[size]; int top; }st; enum Type { operand, oprtor }; /* The Push function Input : A value to be pushed on global stack Output: None, modifies global stack and its top Parameter Passing Method :By Value Called By : Post()
  • 4. Calls :none */ void Push(double Val) { if ( st.top+1 >= size ) printf(―Error: Stack is Fulln‖); st.top++; st.s[st.top] = Val; } /* The Pop function Input : None, uses global stack and top Output: Returns the value on top of stack Parameter Passing Method :None Called By : post() Calls :none */ double Pop() { double Val; if ( st.top == -1 ) printf(―Error: Stack is Emptyn‖); Val = st.s[st.top]; st.top—; return(Val); } /* The gettokn function Input : Given infix expression Output: Returns the next character from the expression Parameter Passing Method : By reference Called By : post() Calls : None */ char gettokn( char exp[]) { static int i = 0; char ch; ch = exp[i]; i++; return ch; } /* The Gettype function Input : A character from infix expression Output: Returns the token type as operand or oprtor Parameter Passing Method : By value Called by : post() Calls : none */ enum Type Gettype(char ch) { ch = toupper(ch); /* convert to upper case */ if ( ch >= ‗0‘ && ch <= ‗9‘) return operand; if ( ch == ‗+‘|| ch == ‗-‘|| ch == ‗*‘|| ch == ‗/‘ ||
  • 5. ch == ‗^‘ ) return oprtor; /* Error */ printf(―Invalid operatorn‖); } /* The post function which contains major logic of the program. Input : A post Expression of single digit operand Output: Resultant value after evaluating the expression Parameter Passing Method :by reference Called By : main() Calls :gettoken(), Push(), Pop() and Gettype() */ double post( char exp[]) { char ch,type; double result, Val, Op1, Op2; st.top = 0; ch = gettokn(exp); while ( ch != ‗$‘ ) { type = Gettype(ch); if( type ==operand) { Val = ch - 48; Push( Val); } else if ( type == oprtor) { Op2 = Pop(); Op1 = Pop(); switch(ch) { case ‗+‘ : result = OP1 + Op2; break; case ‗–‘ : result = Op1 – Op2; break; case ‗*‘ : result = Op1 * Op2; break; case ‗/‘ : result = Op1 / Op2; break; case ‗^‘ : result = pow (Op1 – Op2; break; }/* switch */ Push (result); } ch = gettokn(exp); }/* while */ result = Pop(); return(result); } /* The main function
  • 6. Input : None Output : None Parameter Passing Method : None called By : OS Calls : post() */ void main () { /* Local declarations */ char exp[size]; int len; double Result; clrscr(); printf(―‖Enter the postfix Expressionn"); scanf(―%S‖,exp); len = strlen(exp); exp[len] = ‗‘; /* Append at the end */ Result = post(exp); printf(―The Value of the expression is %fn‖, Result); getch(); exit(0); } / ************** End of the Program ***************** / 3) ‘C’ Program / ********************************************************** Program for conversion of Infix expression to Postfix form. ************************************************************/ #include<stdio.h> #include<conio.h> #include<alloc.h> char inf[40],post[40]; int top=0,st[20]; void postfix(); void push(int); char pop(); /* The main Function Input:none Output:none Called BY:O.S. Calls:postfix */ void main(void) { clrscr(); printf(―ntEnter the infix expression :: nntt‖); scanf(―%s‖, inf); postfix(); getch(); } /* The postfix Function Input:none Output:none
  • 7. Called By:main Calls:push,pop */ void postfix() { int i,j=0; for(i=0;inf[i]!=‘0‘;i++) { switch(inf[i]) { case ‗+‘ : while(st[top] > = 1) post[j++] = pop(); push(1) break; case ‗–‘ : while(st[top] >=1) post[j++] = pop(); push(2); break; case ‗*‘ : while(st[top] >=3) pos[j++] = pop(); push(3) break; case ‗/‘ : while(st[top] > = 3) post[j++] = pop(); push(4); break; case ‗^‘ : while(st[top] >=4) post[j++] = pop(); push(5); break; case ‗(‗ : push(0); break; case ‗)‘ : while(st[top] ! = 0 post[j++] = pop(); top —; break; default : post[j++] = inf[i]; } } while(top>0) post[j++] = pop(); print(―ntPostfix expression is = > nntt %s‖, post); } /* The push Function Input:ele-the element which is to be pushed onto the stack Output:none Called By:postfix Calls:none */ void push(int ele) { top++; st[top] = ele;
  • 8. } /* The pop Function Input:none Output:e-the popped element Called By:postfix Calls:none */ char pop() { int el; char e; el = st[top]; top—; switch(el) { case 1 : e = ‗+‘; break; case 2 : e = ‗–‘; break; case 3 : e = ‗*‘; break; case 4 : e = ‗/‘; break; case 5 : e = ‗^‘; break; } return(e); } /**************** end of program ********************/ 4)C Program /************************************************************ Program for checking the well formedness of the parenthesis. *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 /* stack structure*/ struct stack { char s[size]; int top; }st; /* The push Function Input:item which is to be pushed Output:none-simply pushes the item onto the stck Called By:main Calls:none */ void push(char item) {
  • 9. st.top++; st.s[st.top] =item; } /* The stempty Function Input:none Output:returns 1 or 0 for stack empty or not Called By:main Calls:none */ int stempty() { if(st.top==-1) return 1; else return 0; } /* The pop Function Input:none Output:returns the item which is popped from the stack Called By:main Calls:none */ char pop() { char item; item=st.s[st.top]; st.top—; return(item); } /* The main Function Input:none Output:none Called By:O.S. Calls:push,pop,stempty */ void main(void) { char item; char ans,bracket[10]; int i; st.top=-1; clrscr(); printf(―ntt Enter The expression and put $ at the end‖); scanf(―%s‖,bracket); i=0; if(bracket[i]==‘)‘) printf(―n The expression is invalid‖); else { do {
  • 10. while(bracket[i]==‘(‗) { push(bracket[i]); i++; } while(bracket[i]==‘)‘) { item=pop(); i++; } }while(bracket[i]!=‘$‘); if(!stempty()) printf(―n The expression is invalid‖); else printf(―n The expression has well formed parenthesis‖); } getch(); } 5)C Program /************************************************************* Program for converting decimal number to binary number *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 /* stack structure*/ struct stack { int s[size]; int top; }st; /* The push Function Input:item which is to be pushed Output:none-simply pushes the item onto the stck Called By:main Calls:none */ void push(int item) { st.top++; st.s[st.top] =item; } /* The stempty Function Input:none Output:returns 1 or 0 for stack empty or not Called By:main Calls:none */ int stempty() {
  • 11. if(st.top==-1) return 1; else return 0; } /* The pop Function Input:none Output:returns the item which is popped from the stack Called By:main Calls:none */ int pop() { int item; item=st.s[st.top]; st.top—; return(item); } /* The main Function Input:none Output:none Called By:O.S. Calls:push,pop,stempty */ void main(void) { int item,i,num; st.top=-1; clrscr(); printf(―n Program For Decimal TO Binary Conversion‖); printf(―ntt Enter The number‖); scanf(―%d‖,&num); while(num>=1) { item=num%2; push(item); num=num/2 } while(!stempty()) printf("%d",pop()); getch(); } 6)C Program /************************************************************* Program for reversing the given string using stack *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #define size 10
  • 12. /* stack structure*/ struct stack { char s[size]; int top; }st; /* The push Function Input:item which is to be pushed Output:none-simply pushes the item onto the stck Called By:main Calls:none */ void push(char item) { st.top++; st.s[st.top] =item; } /* The stempty Function Input:none Output:returns 1 or 0 for stack empty or not Called By:main Calls:none */ int stempty() { if(st.top==-1) return 1; else return 0; } /* The pop Function Input:none Output:returns the item which is popped from the stack Called By:main Calls:none */ char pop() { char item; item=st.s[st.top]; st.top—; return(item); } /* The main Function Input:none Output:none Called By:O.S. Calls:push,pop,stempty */ void main(void)
  • 13. { char item,string[10]; int i; st.top=-1; clrscr(); printf(―n Program For reversing a given string‖); printf(―ntt Enter The string:‖); scanf(―%s‖,&string); i=0; while(string[i]!=‘0‘) { push(string[i]); i++; } printf(―ttt‖); while(!stempty()) { item=pop(); printf(―%c‖,item); } getch(); } 7)‘C’ Program /************************************************************* Program to implement multiple stacks using single array *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 20 int stack[MAX]; int size[MAX],lb,ub; /* set_stack Function It is for defining the upper limit and lower limit of each stack Input:the index,which indicates the stack number Output:none,It sets the upper and lower boundries of the stack Called By:stempty,stfull,display,display_all Calls:none Parameter passing method:By value */ void set_stack(int index) { int sum,i; if(index==1) { lb=1; ub=size[index]; } else { sum=0; for(i=1;i<index;i++) sum=sum+size[i];
  • 14. lb=sum+1; ub=sum+size[index]; } } /* stfull Function It checks whether the stack is full or not Input:the index,which indicates the stack number Output:1 if stack is full otherwise 0 Called By:main Calls:set_stack Parameter passing method:By value */ int stfull(int index) { int top,i,sum; set_stack(index); for(top=lb;top<=ub;top++) { if(stack[top]==-1) break; } if(top-1==ub) return 1; else return 0; } /* stempty Function It checks whether the stack is empty or not Input:the index,which indicates the stack number Output:1 if stack is empty otherwise 0 Called By:main Calls:set_stack Parameter passing method:By value */ int stempty(int index) { int top; set_stack(index); for(top=lb;top<=ub;top++) { if(stack[top]!=-1) return 0; return 1; } } /* push Function Input:the item which is to be pushed onto the stack Output:none Called By:main Calls: Parameter passing method:By value */ void push(int item) {
  • 15. int top; for(top=lb;top<=ub;top++) if(stack[top]==-1) break; stack[top]=item; return; } /* pop Function It pops the element from desired stack Input:none Output:item,popped element Called By:main Calls:none */ int pop() { int top,item;; for(top=lb;top<=ub;top++) if(stack[top]==-1) break; top—; item=stack[top]; stack[top]=-1; return item; } /* display Function It displays only desired stack Input:the index,which indicates the stack number Output:none Called By: main Calls:set_stack Parameter passing method:By value */ void display(int index) { int top; set_stack(index); for(top=lb;top<=ub;top++) { if(stack[top]!=-1) printf(―%d‖,stack[top]); } } /* display_all Function It displays all the stacks in the array Input:the n,which indicates total number of stacks Output:none Called By:main Calls:set_stack Parameter passing method:By value */void display_all(int n) { int top,index;
  • 16. for(index=1;index<=n;index++) { printf(―nstack number %d is‖,index); set_stack(index); for(top=lb;top<=ub;top++) { if(stack[top]!=-1) printf(― %d‖,stack[top]); } } } /* main Function Input:none Output:none Called By:O.S. Calls:stfull,push,stempty,pop,display,display_all Parameter passing method: */ void main(void) { int n,index,i,item,choice; char ans; clrscr(); ans=‘y‘; for(i=1;i<=MAX;i++) stack[i]=-1;/*for initialization of the entire array of stacks*/ printf(―nt Program For multiple stacks using single array‖); printf(―n Enter how many stacks are there‖); scanf(―%d‖,&n); printf(―n Enter the size for each stack‖); for(i=1;i<=n;i++) { printf(―n size for stack %d is‖,i); scanf(― %d‖,&size[i]); } do { printf(―ntt Main Menu‖); printf(―n 1.Push n2.Pop n3.Display n4.Dispaly all‖); printf(―n Enter Your choice‖); scanf(―%d‖,&choice); switch(choice) { case 1:printf(―n Enter the item to be pushed‖); scanf(―%d‖,&item); printf(―n In Which stack?‖); scanf(―%d‖,&index); if(stfull(index)) printf(―n Stack %d is Full,can not Push‖,index); else push(item); break; case 2:printf(―n From Which stack?‖); scanf(―%d‖,&index);
  • 17. if(stempty(index)) printf(―n Stack number %d is empty!‖,index); else { item=pop(); printf(―n %d is popped from stack %d‖,item,index); } break; case 3:printf(―n Which stack has to be displayed?‖); scanf(―%d‖,&index); display(index); break; case 4:display_all(n); break; default:printf(―n Exitting‖); } printf(―n Do you wish to continue?‖); ans=getch(); }while(ans==‘y‘||ans==‘Y‘); getch(); } /********************* End Of Program**********************/ 8)C Program /******************************************************************************************* Program for finding out the factorial for any given number. *************************************************************/ #include<stdio.h> #include<stdlib.h> #include<conio.h> /* The fact function Input:the numer n Output: factorial of n Called By:main Calls:itself */ int fact(int n) { int x,y; if(n<0) { printf(―The negative parameter in the factorial function‖); exit(0); } if(n==0) return 1; x=n-1; y=fact(x); return(n*y); } /* The main function Input:none Output:none Called By:O.S.
  • 18. Calls:fact */ void main(void) { int n,f; clrscr(); printf(―ntt Program For finding the factorial of n‖); printf(―nn Enter the number for finding the factorial‖); scanf(―%d‖,&n); f=fact(n); printf(―n the factorial of %d is %d‖,n,f); getch(); } /********************** End Of Program **********************/ 9)C Program /************************************************************* Program for computing the number in the fibonacci series at certain location.For e.g.the sixth number in fibonacci series will be 8.The fibonacci series is 1 1 2 3 5 8 13 21 34... *************************************************************/ /*header files*/ #include<stdio.h> #include<conio.h> /* The fib Function. Input:the location n. Output:the value at that location in fibonacci series. Called By:main. Calls:itself. */ int fib(int n) { int x,y; if(n<=1) return n; x=fib(n-1); y=fib(n-2); return (x+y); } /* The main function Input:none Output:none Called By:o.s Calls:fib-the fibonacci function. */ void main(void) { int n,num; clrscr(); printf(―n Enter location in fibonacci series‖); scanf(―%d‖,&n); num=fib(n); printf(―n The number at %dth position is %d in fibonacci
  • 19. series‖,n,num); getch(); } /********************** End of Program ***********************/ 10)C Program /************************************************************* Program for Multiplication Of natural numbers.The multiplication two numbers is considerd.This is program uses the recurssive definition. *************************************************************/ /*header files*/ #include<stdio.h> #include<conio.h> /************************************************************* mul Function Input:two numbers a,b Output:returns the multiplication result Called by:main Calls:mul i.e.itself *************************************************************/ mul(int a,int b) { if(b==1) return a; else return(mul(a,b-1)+ a); } /************************************************************* main Function Input:none Output:none Called by:O.S. Calls:mul *************************************************************/ main() { int a,b,result=0; clrscr(); printf(―n Enter the values of a and b‖); scanf(―%d%d‖,&a,&b); result=mul(a,b); printf(―The multiplication is =%d‖,result); getch(); } 11)C Program /************************************************************* Program to find out the greatest common divisor of the two integers. *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> int gcd(int a,int b) {
  • 20. int temp,ans; if(b<=a &&a%b ==0) return b; else { if(b<a) { temp = a; a = b; /*interchanging the a and b values*/ b = temp; } ans = a%b; return(gcd(b,ans)); } } void main(void) { int a,b,ans; clrscr(); printf(―ntt GCD Of two integers‖); printf(―nn Enter the two numbers‖); scanf(―%d %d‖,&a,&b); ans=gcd(a,b); printf(―n The gcd of %d and %d is = %d‖,a,b,ans); getch(); } /********************** End of program *******************/ 12)C Program /******************************************************************* Conversion of postfix expression to infix form *******************************************************************/ #include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> typedef struct node { char str[25]; }node; node stack[20]; int top = –1; char input[100]; void post2in(); void push(char *op) { if(top == 20) { printf("nStack full"); exit(0); } top++;
  • 21. strcpy(stack[top].str,op); } char *pop() { char *op; op=(char *)malloc(25); if(top==–1) { printf("ntlllegal expression : operand missing"); exit(0); } strcpy(op,stack[top].str); top--; return(op); } void main() { clrscr(); printf("ntt Program for postfix to infix conversion"); printf("ntEnter postfix expression ::nntt); scanf("%s",input); post2in(); getch(); } void post2in() { char*op1,*op2,op[25]; int i=0; while(input[i]!='0') { if(input[i]!='+'&& input[i]!='–'&& input[i]!='*'&& input[i]!='/') { op[0]=input[i]; op[1]='0'; push(op); } else { op2=pop(); op1=pop(); sprintf(op,"(%s%c%s)",op1,input[i],op2); free(op1); free(op2); push(op); } i++; } if(top==0) {
  • 22. print("ntinfix expression is::nntt%s", stack[0].str); } else { print("ntlllegal input expression:operator missingn"); } } 13)C Program /******************************************************************* Conversion of postfix expression to prefix form *******************************************************************/ #include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> typedef struct node { char str[25]; }node; node stack[20]; int top = –1; char input[100]; void post2pre(); void push(char *op) { if(top == 20) { printf("nStack full"); exit(0); } top++; strcpy(stack[top].str,op); } char *pop() { char *op; op=(char *)malloc(25); if(top==–1) { printf("ntlllegal expression : operand missing"); exit(0); } strcpy(op,stack[top].str); top--; return(op); }
  • 23. void main() { clrscr(); printf("ntt Program for postfix to prefix form"); printf("ntEnter postfix expression ::nntt); scanf("%s",input); post2pre(); getch(); } void post2pre() { char*op1,*op2,op[25]; int i=0; while(input[i]!='0') { if(input[i]!='+'&& input[i]!='–'&& input[i]!='*'&& input[i]!='/') { op[0]=input[i]; op[1]='0'; push(op); } else { op2=pop(); op1=pop(); sprintf(op,"(%c%s%s)",input[i],op1,op2); free(op1); free(op2); push(op); } i++; } if(top==0) { print("ntPrefix expression is::nntt%s", stack[0].str); } else { print("ntlllegal input expression:operator missingn"); } }