fork(2) download
  1. #include <stdio.h>
  2.  
  3. int octal_sum(int a,int b) {
  4. int sum=0, carry=0, d=0, m = 1;
  5. while(a || b || carry) {
  6. d=0;
  7. d=carry+(a%10)+(b%10);
  8. a/=10;b/=10;
  9. if(d>7) {
  10. carry=1;
  11. d=d%8;
  12. } else {
  13. carry = 0;
  14. }
  15. sum += d*m;
  16. m *= 10;
  17. }
  18. return sum; //returns octal sum of a and b
  19. }
  20.  
  21. int main(void) {
  22. printf("%d\n", octal_sum(20, 62));
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
102