Convert decimal to binary using One Dimensional Array in C


This program is about convert and print the given decimal value to binary number using for loops.

Source Code

#include<stdio.h>
int main()
{
  int i,n,a[10];
  printf("\nEnter the Decimal value:");
  scanf("%d",&n);
  for(i=0;n!=0;i++)
  {
    a[i]=n%2;
    n=n/2;
  }
  n=i;
  printf("\nBinary Value:");
  for(i=0;i<n;i++)
  {
    printf("%d",a[n-i-1]);
  }
  return 0;
}

To download raw file Click Here

Output

Enter the Decimal value:20
Binary Value:10100

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes