Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C-program we will Convert the Binary Number into Decimal number and Decimal Number into Binary Number. The number will be taken from the user.
input:
The number.(i.e : 5,6,9[Decimal Number] or 1100,1010,1111[Binary Number] etc.)output:
Binary number will be converted into Decimal number OR Decimal number will be converted into Binary number.
CODE---->
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
long long bin_num,bin;
int dec_num,dec,remainder,i,n;
printf("***************Welcome to Converter***************");
printf("\n\n\n1.Binary to Decimal\n\n2.Decimal to Binary\n\n Enter Your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nPlease, Enter the Binary number : ");
scanf("%lld",&bin_num);
bin=bin_num;
i=0;
dec=0;
while(bin_num!=0)
{
remainder=bin_num%10;
dec=dec+remainder*pow(2,i);
i++;
bin_num=bin_num/10;
}
printf("\nThe decimal of %lld is : %d",bin,dec);
break;
case 2:
printf("\nPlease, Enter the Decimal number : ");
scanf("%d",&dec_num);
dec=dec_num;
i=1;
bin=0;
while(dec_num!=0)
{
remainder=dec_num%2;
dec_num=dec_num/2;
bin=bin+remainder*i;
i=i*10;
}
printf("\nThe binary of %d is : %lld",dec,bin);
break;
default:
printf("\n SORRY !!! You have Entered a wrong choice.");
break;
}
getch();
}
Comments
Post a Comment