Get Update on recent Technology & Programming

Friday, 10 November 2017

C Program to convert a decimal number to binary number

Posted by   on Pinterest



 C Program to convert a decimal number to binary number



#include<stdio.h>

int main(void)

{

 int num,arr[15],i,j;

 printf("Enter a decimal number : ");

 scanf("%d",&num);

 i=0;

 while(num>0)

 {

  arr[i] = num%2; /*store the remainder in array*/

  num/=2;

  i++;

 }

 printf("Binary number is : ");

 for(j=i-1; j>=0; j--)     /*print the array backwards*/

  printf("%d",arr[j]);

 printf("\n");

 return 0;

}



No comments:
Write comments

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter