Ejemplo n.º 1
0
int main()
{
 clrscr();
 int a[10],i,j,k;
 printf("Vvedit 10 chisel:");

 for(i=0;i<10;i++)
  scanf("%d",&a[i]);


 for(i=0,j=0,k=0;i<10;i++)
  {
   if(a[i]%2==0) {putinstack(p1,a[i],j); j++;}
   else {putinstack(p2,a[i],k); k++;}
  }
 puts("\nParni:");
 for(i=0;i<10;i++)
  printf("%d",viewstack(p1,i));
 puts("\n\nNeparni:");
 for(i=0;i<10;i++)
  printf("%d",viewstack(p2,i));


 clearstack(p1);
 clearstack(p2);
 getch();
 return 0;
}
Ejemplo n.º 2
0
/* Exercise 4.5 - other mathematical functions
 * I could add more functions, but you get the idea */
void parseCommand(char s[])
{
    double t;
    
    /* Commands for ex 4.4 - stack commands */
    if (0 == strcmp(s,"view"))
        printtop();     /* view top element on stack */
    else if (0 == strcmp(s, "duplicate"))
        duplicate();    /* duplicate top element on stack */
    else if (0 == strcmp(s, "swap"))
        swap();         /* swap top two elements on stack */
    else if (0 == strcmp(s, "clear"))
        clear();        /* clear stack */

    /* Commands for 4.5 - maths functions */
    else if (0 == strcmp(s,"sin")) 
        push(sin(pop()));
    else if (0 == strcmp(s,"exp")) 
        push(exp(pop()));
    else if (0 == strcmp(s,"pow")) {
        t = pop();
        push(pow(pop(),t));
    }

    /* misc functions */
    else if (0 == strcmp(s, "stack"))
        viewstack();
    else if (0 == strcmp(s, "vars"))
        viewvars();
    else
        printf("error: not a valid command\n");
}