-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdec2all.c
executable file
·70 lines (62 loc) · 1.53 KB
/
dec2all.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* =====================================================================================
*
* Filename: dec2all.c
*
* Description: Zamiana z systemu dziesietnego do systemu o innej podstawie 2-9.
*
* Version: 1.0
* Created: 05.12.2013 23:14:36
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
/* Funkcja wyswietla w odwrotnej kolejnosci 'n' liczb dziesietnych z tablicy 't */
void wypisz(int *t,int n)
{
while( n > 0 )
{
n = n - 1;
if( t[n] < 10 ) printf("%d",t[n]);
else if ( t[n] < 10 + 'Z' - 'A' ) printf("%c",t[n] - 10 + 'A');
else printf("[%d]",t[n]);
}
}
/* Funkcja zamienia liczbe 'x' zapisujac ja w systemie pozycyjnym o podstawie 'p'.
* Kolejne cyfry zapisane sa w tablicy 't[]'.
* Tablica 't[]' powinna miec rozmiar dostatecznie duzy aby
* pomiescic liczbe w nowej reprezentacji (wystarcza 32 elementy)
* Funkcja zwraca ilosc cyfr umieszczonych w tablicy. */
int zmien_podstawe(int x, int *t, int p)
{
int i=0;
while( x != 0 )
{
t[i] = x % p;
x = x / p;
i = i + 1;
}
return i;
}
int main()
{
int t[32], x, n, i;
printf("Liczba dziesietna: ");
scanf("%d",&x);
i=2;
while( i<=16 )
{
n=zmien_podstawe(x,t,i);
printf("%d: ",i);
wypisz(t,n);
printf("\n");
i = i + 1;
}
return 0;
}