Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     printf("Program wykonuje konwersje miedzy dowolnymi systemami liczbowymi, z systemu dziesietnego i na system dziesietny.\nLICZBY CALKOWITE DODATNIE!\n");
  7.     printf("Prosze postepowac zgodnie z instrukcjami i nie wpisywac innych wartosci niz wymagane. Max 16 BIT!\n");
  8.     printf("\nJezeli chcesz konwertowac z 10 na D (2-16) wpisz 1\n");
  9.     printf("Jezeli chcesz konwertowac z D (2-16) na 10 wpisz 0\n");
  10.     int D, S, L;
  11.     scanf("%d", &S);
  12.     if(S==1)
  13.     {
  14.         printf("Podaj D\n");
  15.         scanf("%d", &D);
  16.         printf("Podaj liczbe w systemie, ktory zostal wybrany = ");
  17.         int x;
  18.         scanf("%d", &x);
  19.         int  i=0, j;
  20.         char tab[16];
  21.         for(j=15;j>=0;j--)
  22.         {
  23.            tab[j]='-';
  24.         }
  25.  
  26.         do
  27.         {
  28.             tab[i]=x%D;
  29.             x=x/D;
  30.             i++;
  31.         }
  32.         while(x>=1);
  33.         printf("Liczba w systemie %d to\n", D);
  34.         for(j=15;j>=0;j--)
  35.         {
  36.             if(tab[j]==10)
  37.             {
  38.                printf("A");
  39.             }
  40.             if(tab[j]==11)
  41.             {
  42.                printf("B");
  43.             }
  44.             if(tab[j]==12)
  45.             {
  46.                printf("C");
  47.             }
  48.             if(tab[j]==13)
  49.             {
  50.                printf("D");
  51.             }
  52.             if(tab[j]==14)
  53.             {
  54.                printf("E");
  55.             }
  56.             if(tab[j]==15)
  57.             {
  58.                printf("F");
  59.             }
  60.             if(tab[j]<10)
  61.             {
  62.                 printf("%d", tab[j]);
  63.             }
  64.         }
  65.     }
  66.     else
  67.     {
  68.         int V;
  69.         printf("Jezeli chcesz konwertowac z systemow (2-10) wpisz 1\n");
  70.         printf("Jezeli chcesz konwertowac z systemow (11-16) wpisz 0\n");
  71.         scanf("%d", &V);
  72.         if(V==1)
  73.             {
  74.             printf("Podaj D(2-10)\n");
  75.             scanf("%d", &D);
  76.             printf("Podaj liczbe w wybranym systemie = ");
  77.             int x;
  78.             scanf("%d", &x);
  79.             int i=0, y=0;
  80.             do
  81.             {
  82.                 if(x%10>0)
  83.                 {
  84.                     y=y+(x%10)*(pow(D,i));
  85.                 }
  86.                 x=x/10;
  87.                 i++;
  88.             }
  89.             while(x>=1);
  90.             printf("Liczba w systemie 10 = %d", y);
  91.             }
  92.         else
  93.         {
  94.             printf("Podaj D(11-16)\n");
  95.             scanf("%d", &D);
  96.             printf("Podaj ilosc cyfr/znakow z ktorej bedzie sie skladala liczba\n");
  97.             scanf("%d", &L);
  98.             printf("Podaj liczbe, po kazdym elemencie klikajac klawisz ENTER\n");
  99.             printf("Wpisujac element wiekszy od 9, posluguj sie wielkimi literami czyli ABCDEF\n");
  100.             int x;
  101.             int i=0, y=0, k, wynik=0;
  102.             int tabtemp[200];
  103.             for(k=0;k<L;k++)
  104.             {
  105.                 char asd[1];
  106.                 scanf("%s", &asd);
  107.  
  108.                 if(strcmp(asd,"A")==0)
  109.                 {
  110.                     tabtemp[k]=10;
  111.                 }
  112.                 else if(strcmp(asd,"B")==0)
  113.                 {
  114.                     tabtemp[k]=11;
  115.                 }
  116.                 else if(strcmp(asd,"C")==0)
  117.                 {
  118.                     tabtemp[k]=12;
  119.                 }
  120.                 else if(strcmp(asd,"D")==0)
  121.                 {
  122.                     tabtemp[k]=13;
  123.                 }
  124.                 else if(strcmp(asd,"E")==0)
  125.                 {
  126.                     tabtemp[k]=14;
  127.                 }
  128.                 else if(strcmp(asd,"F")==0)
  129.                 {
  130.                     tabtemp[k]=15;
  131.                 }
  132.                 else
  133.                 {
  134.                     tabtemp[k]=(char)asd[0]-'0';
  135.                 }
  136.                 wynik=wynik+tabtemp[k]*(pow(D,L-k-1));
  137.             }
  138.  
  139.             printf("\nLiczba w systemie 10 = %d",wynik);
  140.  
  141.         }
  142.  
  143.  
  144.     }
  145.  
  146.  
  147.  
  148.     printf("\n\nProgram wykonal Pawel Paszkowski\n\n");
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement