Thread: please help me in c

  1. #1
    jatinder
    Guest

    please help me in c

    I am stuck i don't know what to do can anyone please help me on this project i have to do this if i type a expresstion it should give me the answer like this 2+3/3*4+2 and it should give me 8.
    And u can also type in spaces when u r writing the expresstion and it should not see the spaces. And u have to use stacks and NO pointers. PUSH AND POP

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    An array can be used as a stack very simply:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int stack[100];
      int i, n = 0;
    
      /* Push four values */
      for ( i = 1; i < 5; i++ )
        stack[n++] = i;
    
      /* Pop all values */
      while ( n > 0 )
        printf ( "%d\n", stack[--n] );
    
      return 0;
    }
    Now you should have no problem placing those operations in separate functions and performing the appropriate calculations when you pop.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed