#include<stdio.h>
#include<stdlib.h>

int main()
{
       int number,findDigit,i=0,resudual;
       char *binary;

       printf("Decimal Sayi : ");
       scanf("%d",&number); // number=18

       findDigit = number; // findDigit=18

       while(findDigit != 1){
             findDigit = findDigit/2; // 18/2=9 | 9/2=4 | 4/2=2 | 2/2=1
             i++; // i = 4
       }

       binary = (char *) malloc((i+1)*sizeof(char)); // 5 elemanli bir dinamik dizi.

       binary[i+1] = NULL; // 5.elemana '\0' karakteri ataniyor.

       while(number != 0){
             if(number%2 == 1) {
                 binary[i] = '1'; resudual=1; //
             }
                else {
                    binary[i] = '0'; resudual=0; // binary[4] = 0 || binary[3] = 1 || binary[2] = 0 || binary[1] = 0 || binary[0] = 1
                }
             number =(number - resudual)/2;       // number   = 9 || number    = 4 || number    = 2 || number    = 1 || number    = 0
             i--;
       }

       printf("\nAs Binary : %s",binary);

       return 0;
}
