Question: Please help with programming in C : Adding code to the below programming so that the result can be saved as a text file. #
Please help with programming in C : Adding code to the below programming so that the result can be saved as a text file.
# include
int main()
{
int number;
while(1)
{ printf("Enter a number:");
scanf("%d",&number);
printf("Hexadecimal: %x ",number);
//Convert Decimal to Binary
int bin[100], c=1, i;
while(number != 0)
{
bin[c++] = number % 2;
number = number/2;
}
for(i=c-1; i>0; i--)
printf("%d",bin[i]);
printf(" ");
}
return(0);
}
The output should be shown as the following if the entered number is 100:
Hexadec is 64
Binary is 1100100
Do you want to save the output?: y ( if yes, asking the user to enter the name of the file, if no, ask the user to enter another number)
Enter the name of the file
File is saved
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
