Decimal to binary conversion using c

Program:
#include<stdio.h>
main()
{
    int arr[15];
    int i,j,n,num,rem;
    printf("Enter the number:");
    scanf("%d",&num);
    i=0;
    while(num>0)
    {
        arr[i]=num%2;
        num /=2;
        i++;
    }
   
    printf("i=%d\n",i);
    printf("The Binary value of given number: ");
    for(j=i-1;j>=0;j--)
    {
        printf("%d",arr[j]);
        }
    return 0;
}
Output:
Enter the number:10                                                                                                                                      
i=4                                                                                                                                                      
The Binary value of given number: 1010  

Comments

Popular Posts