Also understand that defining
register
does not mean that the variable will be stored in a
register; rather, it means that it might be stored in a register—depending on hardware and
implementation restrictions.
Before we close this chapter, let us write some programs now.
Q1.
Write a C program to convert a binary number to a decimal number.
Ans. 1:
The program is as follows:
#include
main( )
{
int binary, bin, digit, decimal=0, base=0;
printf(“\n\t Enter any binary number:”);
scanf(“%d”, &binary);
bin = binary;
while (binary !=0)
{
digit = binary % 10;
digit = digit << base;
decimal = decimal + digit;
base++;
binary = binary / 10;
}
printf(“\n Decimal equivalent of binary number %d = %d”, bin, decimal);
}
Do'stlaringiz bilan baham: |