abC primeri - funkcije/racunalo2.c

racunalo2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main(int argc, char *argv[]) {
  int i;
  char *s;

  // namesto int x = atoi(argv[1]);
  int x=0;
  s = argv[1];  
  i = 0;
  while (i<strlen(s)) {
    x = 10*x + (s[i++]-'0');
  }

  // namesto int y = atoi(argv[2]);
  int y=0;
  s = argv[2];  
  i = 0;
  while (i<strlen(s)) {
    y = 10*y + (s[i++]-'0');    
  }

  printf("%d + %d = %d\n", x, y, x+y);
}

    Nazaj...