C 9
Task9 By zlax on 7th December 2024 02:45:14 PM
  1. #include <stdio.h>
  2. #define BASE 7
  3.  
  4. unsigned long int BASEto10(unsigned long int);
  5. unsigned long int DECtoBASE(unsigned long int);
  6. long long int BASEaddition(unsigned long int, unsigned long int);
  7. long long int BASEsubtraction(unsigned long int, unsigned long int);
  8. long long int BASEmultiplication(unsigned long int, unsigned long int);
  9.  
  10. int main(void) {
  11.     unsigned long int a,b,c;
  12.     scanf("%ld", &a);
  13.     scanf("%ld", &b);
  14.     if (BASEsubtraction(a, b) >= 0) {
  15.         c = BASEsubtraction(a, b);
  16.         if (BASEmultiplication(a, c) >= 0) {
  17.                 c = BASEmultiplication(a, c);
  18.                 if (BASEaddition(c, a) >= 0) {
  19.                         c = BASEaddition(c, a);
  20.                 printf("%d\n", c);
  21.                 } else printf("!1\n");
  22.         } else printf("!3\n");
  23.     } else printf("!2\n");
  24.     return 0;
  25. }
  26.  
  27. unsigned long int BASEto10(unsigned long int a) {
  28.     if (a == 0) return 0;
  29.         int k=1;
  30.         long int a10=0;
  31.         while (a) {
  32.             a10 += k*(a%10);
  33.             k *= BASE;
  34.             a /= 10;
  35.         }
  36.         return a10;
  37. }
  38.  
  39. unsigned long int DECtoBASE(unsigned long int a) {
  40.     if (a == 0) return 0;
  41.         return (a % BASE) + 10 * DECtoBASE(a / BASE);
  42. }
  43.  
  44. long long int BASEaddition(unsigned long int a, unsigned long int b) {
  45.         long long int c = BASEto10(a) + BASEto10(b);
  46.         if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c);
  47.         return -1;
  48. }
  49.  
  50. long long int BASEsubtraction(unsigned long int a, unsigned long int b) {
  51.         long long int c = BASEto10(a) - BASEto10(b);
  52.         if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c);
  53.         return -1;
  54. }
  55.  
  56. long long int BASEmultiplication(unsigned long int a, unsigned long int b) {
  57.         long long int c = BASEto10(a) * BASEto10(b);
  58.         if ((DECtoBASE(c) < 4266666666) && (DECtoBASE(c) >= 0)) return DECtoBASE(c);
  59.         return -1;
  60. }

Paste is for source code and general debugging text.

Raw Paste

Login or Register to edit or fork this paste. It's free.