1#include <stdio.h>
2
3void main()
4{
5 int n;
6 long long bin = 0;
7 int j,rem, i = 1;
8
9 printf("Enter a decimal number: ");
10 scanf("%d", &n);
11
12
13 for(j=n;j!=0;j)
14 {
15 rem = j % 2;
16 j /= 2;
17 bin += rem * i;
18 i *= 10;
19 }
20
21 printf("%d in decimal = %lld in binary",n,bin);
22}
1#include <math.h>
2#include <stdio.h>
3int convert(long long n);
4int main() {
5 long long n;
6 printf("Enter a binary number: ");
7 scanf("%lld", &n);
8 printf("%lld in binary = %d in decimal", n, convert(n));
9 return 0;
10}
11
12int convert(long long n) {
13 int dec = 0, i = 0, rem;
14 while (n != 0) {
15 rem = n % 10;
16 n /= 10;
17 dec += rem * pow(2, i);
18 ++i;
19 }
20 return dec;
21}
22
1#include <stdio.h>
2#include <math.h>
3#include <stdlib.h>
4
5#define D 10
6
7int main()
8{
9 int i, n, k, vet[D];
10
11 printf("FROM DECIMALS TO BINARIES\nEnter decimal: ");
12 scanf("%d", &n);
13
14 k = 0;
15
16 while (n != 0)
17 {
18 if ((n % 2) == 1)
19 vet[k] = 1;
20 else
21 vet[k] = 0;
22
23 n /= 2;
24
25 k++;
26 }
27
28 printf("Transformed into binary: ");
29
30 for(i = k - 1; i >= 0; i --)
31 printf("%d", vet[i]);
32
33 printf("\n\n");
34
35 system("pause");
36}