Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- int main()
- {
- printf("Program wykonuje konwersje miedzy dowolnymi systemami liczbowymi, z systemu dziesietnego i na system dziesietny.\nLICZBY CALKOWITE DODATNIE!\n");
- printf("Prosze postepowac zgodnie z instrukcjami i nie wpisywac innych wartosci niz wymagane. Max 16 BIT!\n");
- printf("\nJezeli chcesz konwertowac z 10 na D (2-16) wpisz 1\n");
- printf("Jezeli chcesz konwertowac z D (2-16) na 10 wpisz 0\n");
- int D, S, L;
- scanf("%d", &S);
- if(S==1)
- {
- printf("Podaj D\n");
- scanf("%d", &D);
- printf("Podaj liczbe w systemie, ktory zostal wybrany = ");
- int x;
- scanf("%d", &x);
- int i=0, j;
- char tab[16];
- for(j=15;j>=0;j--)
- {
- tab[j]='-';
- }
- do
- {
- tab[i]=x%D;
- x=x/D;
- i++;
- }
- while(x>=1);
- printf("Liczba w systemie %d to\n", D);
- for(j=15;j>=0;j--)
- {
- if(tab[j]==10)
- {
- printf("A");
- }
- if(tab[j]==11)
- {
- printf("B");
- }
- if(tab[j]==12)
- {
- printf("C");
- }
- if(tab[j]==13)
- {
- printf("D");
- }
- if(tab[j]==14)
- {
- printf("E");
- }
- if(tab[j]==15)
- {
- printf("F");
- }
- if(tab[j]<10)
- {
- printf("%d", tab[j]);
- }
- }
- }
- else
- {
- int V;
- printf("Jezeli chcesz konwertowac z systemow (2-10) wpisz 1\n");
- printf("Jezeli chcesz konwertowac z systemow (11-16) wpisz 0\n");
- scanf("%d", &V);
- if(V==1)
- {
- printf("Podaj D(2-10)\n");
- scanf("%d", &D);
- printf("Podaj liczbe w wybranym systemie = ");
- int x;
- scanf("%d", &x);
- int i=0, y=0;
- do
- {
- if(x%10>0)
- {
- y=y+(x%10)*(pow(D,i));
- }
- x=x/10;
- i++;
- }
- while(x>=1);
- printf("Liczba w systemie 10 = %d", y);
- }
- else
- {
- printf("Podaj D(11-16)\n");
- scanf("%d", &D);
- printf("Podaj ilosc cyfr/znakow z ktorej bedzie sie skladala liczba\n");
- scanf("%d", &L);
- printf("Podaj liczbe, po kazdym elemencie klikajac klawisz ENTER\n");
- printf("Wpisujac element wiekszy od 9, posluguj sie wielkimi literami czyli ABCDEF\n");
- int x;
- int i=0, y=0, k, wynik=0;
- int tabtemp[200];
- for(k=0;k<L;k++)
- {
- char asd[1];
- scanf("%s", &asd);
- if(strcmp(asd,"A")==0)
- {
- tabtemp[k]=10;
- }
- else if(strcmp(asd,"B")==0)
- {
- tabtemp[k]=11;
- }
- else if(strcmp(asd,"C")==0)
- {
- tabtemp[k]=12;
- }
- else if(strcmp(asd,"D")==0)
- {
- tabtemp[k]=13;
- }
- else if(strcmp(asd,"E")==0)
- {
- tabtemp[k]=14;
- }
- else if(strcmp(asd,"F")==0)
- {
- tabtemp[k]=15;
- }
- else
- {
- tabtemp[k]=(char)asd[0]-'0';
- }
- wynik=wynik+tabtemp[k]*(pow(D,L-k-1));
- }
- printf("\nLiczba w systemie 10 = %d",wynik);
- }
- }
- printf("\n\nProgram wykonal Pawel Paszkowski\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement