Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main
- /*
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- double compute (int *idx, char *t[])
- {
- char op=t[*idx][0];
- double left, right;
- if (strchr("+-/*", op)==NULL)
- return atof(t[*idx]);
- switch (op){
- case '+':
- (*idx)++; left=compute(idx, t);
- (*idx)++, right=compute(idx, t);
- return left+right;
- case '-':
- (*idx)++; left=compute(idx, t);
- (*idx)++, right=compute(idx, t);
- return left-right;
- case '*':
- (*idx)++; left=compute(idx, t);
- (*idx)++, right=compute(idx, t);
- return left*right;
- case '/':
- (*idx)++; left=compute(idx, t);
- (*idx)++, right=compute(idx, t);
- return left/right;
- }
- return 0.0;
- }
- int main (int argc, char *argv[])
- {
- if (argc<=1){
- fprintf(stderr, "keves argumentum!\n");
- return EXIT_FAILURE;
- }
- else {
- int index=1;
- printf("%f\n", compute(&index, argv));
- return EXIT_SUCCESS;
- }
- return EXIT_SUCCESS;
- }
- /*
- //rendezΓ©s
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main (int argc, char *argv[])
- {
- int i;
- int osszeg=0;
- for (i=0; i<=argc; i++)
- osszeg+=atoi(argv[i]);
- printf("osszeg=%d\n", osszeg);
- return EXIT_SUCCESS;
- }
- */
- /*
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int compare(const void *a, const void *b){
- return strcmp(*(char **)a, *(char **)b);
- }
- int main (int argc, char *argv[])
- {
- int i;
- printf("argc=%d\n", argc);
- qsort(argv+1, argc-1, sizeof(char *), compare);
- for (i=0; i<=argc; i++)
- printf("%2d: |%s|\n", i, argv[i]);
- return EXIT_SUCCESS;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement