Advertisement
zsoltizbekk

asdqwe

Apr 29th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main
  6.  
  7. /*
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. double compute (int *idx, char *t[])
  13. {
  14.     char op=t[*idx][0];
  15.     double left, right;
  16.     if (strchr("+-/*", op)==NULL)
  17.         return atof(t[*idx]);
  18.     switch (op){
  19.         case '+':
  20.             (*idx)++; left=compute(idx, t);
  21.             (*idx)++, right=compute(idx, t);
  22.             return left+right;
  23.         case '-':
  24.             (*idx)++; left=compute(idx, t);
  25.             (*idx)++, right=compute(idx, t);
  26.             return left-right;
  27.         case '*':
  28.             (*idx)++; left=compute(idx, t);
  29.             (*idx)++, right=compute(idx, t);
  30.             return left*right;
  31.         case '/':
  32.             (*idx)++; left=compute(idx, t);
  33.             (*idx)++, right=compute(idx, t);
  34.             return left/right;
  35.         }
  36.         return 0.0;
  37. }
  38.  
  39. int main (int argc, char *argv[])
  40. {
  41.     if (argc<=1){
  42.         fprintf(stderr, "keves argumentum!\n");
  43.         return EXIT_FAILURE;
  44.     }
  45.     else {
  46.         int index=1;
  47.     printf("%f\n", compute(&index, argv));
  48.     return EXIT_SUCCESS;
  49.     }
  50.  
  51.     return EXIT_SUCCESS;
  52. }
  53. /*
  54.  
  55. //rendezΓ©s
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60.  
  61.  
  62. int main (int argc, char *argv[])
  63. {
  64.     int i;
  65.     int osszeg=0;
  66.     for (i=0; i<=argc; i++)
  67.         osszeg+=atoi(argv[i]);
  68.     printf("osszeg=%d\n", osszeg);
  69.     return EXIT_SUCCESS;
  70. }
  71. */
  72.  
  73. /*
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <string.h>
  77.  
  78. int compare(const void *a, const void *b){
  79. return strcmp(*(char **)a, *(char **)b);
  80. }
  81.  
  82. int main (int argc, char *argv[])
  83. {
  84.     int i;
  85.     printf("argc=%d\n", argc);
  86.  
  87.     qsort(argv+1, argc-1, sizeof(char *), compare);
  88.  
  89.     for (i=0; i<=argc; i++)
  90.         printf("%2d: |%s|\n", i, argv[i]);
  91.     return EXIT_SUCCESS;
  92. }
  93.  
  94.  
  95. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement