Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #define BASE 9
- long int BASEto10(long int a);
- long int OBRATNO(long int b);
- int main(void)
- {
- long int x, y;
- long int n, m;
- printf("Ternary notation: (input only digits 0,1,2,3,4,5,6,7,8) a=");
- scanf("%ld", &x);
- y = BASEto10(x);
- printf("Decimal notation: a=%ld\n", y);
- printf("Input new decimal notation: b = ");
- scanf("%ld", &n);
- m = OBRATNO(n);
- printf("Ternary notation: b=%ld\n", m);
- return 0;
- }
- long int BASEto10(long int a) {
- int k=1;
- long int a10=0;
- while (a) {
- a10 += k*(a%10);
- k *= 9;
- a /= 10;
- }
- return a10;
- }
- long int OBRATNO(long int b)
- { //perevod iz 10 v 9
- int p=1;
- long int b9=0;
- while (b) {
- b9 += p*(b%9);
- p *= 10;
- b /= 9;
- }
- return b9;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement