fork download
  1. # define max 1000
  2. char arr[max];
  3. void subtract(char *a1,char *b1)
  4. {
  5. int l1,l2;
  6. char temp[max],a[max],b[max];
  7. int c=0,sub=0,m=0;
  8. int i,j,k=0;
  9.  
  10. for(i=strlen(a1)-1;i>=0;i--)
  11. a[k++]=a1[i];
  12.  
  13. a[k]='\0';k=0;
  14. for(i=strlen(b1)-1;i>=0;i--)
  15. b[k++]=b1[i];
  16. b[k]='\0';
  17.  
  18. printf("%s %s\n",a,b);
  19. l1=strlen(a);
  20. l2=strlen(b);
  21. if(l2>l1)
  22. {
  23. strcpy(temp,b);
  24. strcpy(b,a);
  25. strcpy(a,temp);
  26. }
  27. l1=strlen(a);
  28. l2=strlen(b);
  29. k=0;
  30. for(i=0;i<l2;i++)
  31. {
  32. int n1=a[i]-'0';
  33. int n2=b[i]-'0';
  34. sub=n1-n2-c;
  35. if(sub<0)
  36. {
  37. sub=10-sub;c=1;
  38. arr[k++]=sub+'0';
  39.  
  40. }
  41. else {c=0;arr[k++]=sub+'0'};
  42. }
  43.  
  44. for(i=l2;i<l1;i++)
  45. {
  46. int n1=a[i]-'0';
  47. sub=n1-c;
  48. if(sub<0)
  49. {
  50. sub=10-sub;c=1;
  51. arr[k++]=sub+'0';
  52. }
  53. else {c=0;arr[k++]=sub+'0';}
  54. }
  55. arr[k]='\0';
  56.  
  57. printf("arr=%s\n",arr);
  58.  
  59. for(i=strlen(arr)-1;i>=0;i--)
  60. printf("%c",arr[i]);
  61.  
  62. return arr;
  63. }
  64.  
  65.  
  66. int main()
  67. {
  68. char a[max],b[max],c[max];
  69. scanf("%s %s",a,b);
  70. subtract(a,b);
  71. return 0;
  72. }
  73.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
9999 123
compilation info
prog.c: In function ‘subtract’:
prog.c:10: warning: implicit declaration of function ‘strlen’
prog.c:10: warning: incompatible implicit declaration of built-in function ‘strlen’
prog.c:18: warning: implicit declaration of function ‘printf’
prog.c:18: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:23: warning: implicit declaration of function ‘strcpy’
prog.c:23: warning: incompatible implicit declaration of built-in function ‘strcpy’
prog.c:41: error: expected ‘;’ before ‘}’ token
prog.c:62: warning: ‘return’ with a value, in function returning void
prog.c:8: warning: unused variable ‘j’
prog.c:7: warning: unused variable ‘m’
prog.c: In function ‘main’:
prog.c:69: warning: implicit declaration of function ‘scanf’
prog.c:69: warning: incompatible implicit declaration of built-in function ‘scanf’
prog.c:68: warning: unused variable ‘c’
stdout
Standard output is empty