JAVA, C#, VB.6.0, SQL, C, Computer Sci Free Computer Programming Tutorials: http://bagadhicomputersciencetutorials.blogspot.com/
Thursday, 4 January 2018
C Program to Convert a Number Decimal System to Binary System using Recursion
/*
* C Program to Convert a Number Decimal System to Binary System using Recursion
*/
#include <stdio.h>
int convert(int);
int main()
{ int dec, bin;
printf("Enter a decimal number: ");
scanf("%d", &dec);
bin = convert(dec);
printf("The binary equivalent of %d is %d.\n", dec, bin);
return 0;
}
int convert(int dec)
{
if (dec == 0)
{
return 0;
}
else
{
return (dec % 2 + 10 * convert(dec / 2));
}
}
output:-
* C Program to Convert a Number Decimal System to Binary System using Recursion
*/
#include <stdio.h>
int convert(int);
int main()
{ int dec, bin;
printf("Enter a decimal number: ");
scanf("%d", &dec);
bin = convert(dec);
printf("The binary equivalent of %d is %d.\n", dec, bin);
return 0;
}
int convert(int dec)
{
if (dec == 0)
{
return 0;
}
else
{
return (dec % 2 + 10 * convert(dec / 2));
}
}
output:-
Enter a decimal number: 10 The binary equivalent of 10 is 1010
Decimal to Binary conversion using C
/*
* C Program to Print Binary Equivalent of an Integer using Recursion
*/
#include <stdio.h>
int binary_conversion(int);
int main()
{
int num, bin;
printf("Enter a decimal number: ");
scanf("%d", &num);
bin = binary_conversion(num);
printf("The binary equivalent of %d is %d\n", num, bin);
}
int binary_conversion(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * binary_conversion(num / 2);
}
}
* C Program to Print Binary Equivalent of an Integer using Recursion
*/
#include <stdio.h>
int binary_conversion(int);
int main()
{
int num, bin;
printf("Enter a decimal number: ");
scanf("%d", &num);
bin = binary_conversion(num);
printf("The binary equivalent of %d is %d\n", num, bin);
}
int binary_conversion(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * binary_conversion(num / 2);
}
}
Subscribe to:
Posts (Atom)