Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #define BASE 9
  5.  
  6. long int BASEto10(long int a);
  7. long int OBRATNO(long int b);
  8. int main(void)
  9. {
  10. long int x, y;
  11. long int n, m;
  12. printf("Ternary notation: (input only digits 0,1,2,3,4,5,6,7,8) a=");
  13. scanf("%ld", &x);
  14. y = BASEto10(x);
  15. printf("Decimal notation: a=%ld\n", y);
  16. printf("Input new decimal notation: b = ");
  17. scanf("%ld", &n);
  18. m = OBRATNO(n);
  19. printf("Ternary notation: b=%ld\n", m);
  20. return 0;
  21. }
  22. long int BASEto10(long int a) {
  23. int k=1;
  24. long int a10=0;
  25. while (a) {
  26. a10 += k*(a%10);
  27. k *= 9;
  28. a /= 10;
  29. }
  30. return a10;
  31. }
  32. long int OBRATNO(long int b)
  33. { //perevod iz 10 v 9
  34. int p=1;
  35. long int b9=0;
  36. while (b) {
  37. b9 += p*(b%9);
  38. p *= 10;
  39. b /= 9;
  40. }
  41. return b9;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement