Question: The following C program asks the user to enter a decimal number. It then uses an integer array to store the values of the remainders
The following C program asks the user to enter a decimal number. It then uses an integer array to store the values of the remainders after repeatedly dividing the users input by 2. Finally, the array values representing the binary equivalent will be printed out to the user.
Rewrite the program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output.
The two prototypes should be the following:
intbtod(intsize, charinputBin[size]);
intdtob(intinputDec);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1. Declare needed variables
2. Prompt user to enter a binary number
3. Use scanf() to get that value
4. If getting it as a string, use strlen() to find the length of the string
5. Call btod() function sending to it the size and the value that was entered by the user and save the return value so the result can be printed out
6. Prompt user to enter a decimal number
7. Use scanf() to get that value
8. Call dtob() function saving the return value in a variable so the result can be printed out
Dont forget to break the program into smaller steps and compile and run AFTER EACH STEP
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include #include int main(){ int a[10],n,i; system ("cls"); printf("Enter the number to convert: "); scanf("%d",&n); for(i=0;n>0;i++) { a[i]=n%2; n=n/2; } printf(" Binary of Given Number is "); for(i=i-1;i>=0;i--) { printf("%d",a[i]); } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
