Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5.     printf("Program wykonuje konwersje miedzy dowolnymi systemami liczbowymi od dwojkowego do dziesietnego.\n");
  6.     printf("Prosze postepowac zgodnie z instrukcjami i nie wpisywac innych wartosci niz wymagane.\n");
  7.     printf("Jezeli chcesz zamienic z 10 na D wpisz 1\n");
  8.     printf("Jezeli chcesz zamienic z D na 10 wpisz 0\n");
  9.     int D, S;
  10.     scanf("%d", &S);
  11.     printf("Podaj D\n");
  12.     scanf("%d", &D);
  13.     printf("Podaj liczbe w systemie, ktory zostal wybrany = ");
  14.     int x;
  15.     scanf("%d", &x);
  16.     if(S==1)
  17.     {
  18.         int  i=0, tab[16], j;
  19.         for(j=15;j>=0;j--)
  20.         {
  21.            tab[j]=0;
  22.         }
  23.  
  24.         do
  25.         {
  26.             tab[i]=x%D;
  27.             x=x/D;
  28.             i++;
  29.         }
  30.         while(x>=1);
  31.         printf("Liczba w systemie %d to\n", D);
  32.         for(j=15;j>=0;j--)
  33.         {
  34.             printf("%d", tab[j]);
  35.         }
  36.     }
  37.     else
  38.     {
  39.         int i=0, y=0;
  40.         do
  41.         {
  42.             if(x%10>0)
  43.             {
  44.                 y=y+(x%10)*(pow(D,i));
  45.                 printf("y dla %d to %d\n",i, y);
  46.             }
  47.             x=x/10;
  48.             i++;
  49.         }
  50.         while(x>=1);
  51.         printf("Liczba w systemie 10 to %d", y);
  52.     }
  53.  
  54.  
  55.     printf("\n\nProgram wykonal Pawel Paszkowski\n\n");
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement