BHARATHIAR UNIVERSITY
BCA and B.Sc Programs - Programming in C Lab - Bharathiar University - Practical Program-
C Program to Write a C Program to convert decimal number to binary number
Source Code
#include <stdio.h>
#include <conio.h>
void decimalToBinary(int decimal)
{
int binary[32];
int index = 0,i;
while (decimal > 0)
{
binary[index++] = decimal % 2;
decimal /= 2;
}
printf("Binary representation: ");
for (i = index - 1; i >= 0; i--)
{
printf("%d", binary[i]);
} printf("\n");
}
int main()
{
int decimal;
clrscr();
printf("Enter a decimal number: ");
scanf("%d", &decimal);
decimalToBinary(decimal);
getch();
return 0;
}
OUTPUT:
No comments:
Post a Comment