Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include int getche(void); char* getDateAndTime(); long DecimaltoBinary(long n); int main(){ long Decimal = 240; do { printf(Enter an Integer (1 1000000) or type x

image text in transcribed

image text in transcribed

#include

#include

int getche(void);

char* getDateAndTime();

long DecimaltoBinary(long n);

int main(){

long Decimal = 240;

do {

printf("Enter an Integer (1 1000000) or type x to exit: ");

scanf("%d", &Decimal);

}while(Decimal 1000000);

printf("Decimal: %d ", Decimal);

printf("Hexadecimal: %x ", Decimal);

printf("Octal: %o ", Decimal);

printf("Binary: %ld ", DecimaltoBinary(Decimal));

return 0;

}

/* Funccton to convert a binary number to decimal number */

long DecimaltoBinary(long n){

int remainder;

long binary = 0, i = 1;

while(n != 0){

remainder = n%2;

n = n/2;

binary= binary + (remainder*i);

i = i*10;

}

return binary;

}

printf("Save to file? (y): ");

ch=getche();

if(ch=='y')

{

printf(" enter the file name:");

scanf("%s",&file);

FILE *fptr;

fptr = fopen(file, "w");

if(fptr == NULL)

{

printf("Error!");

return 1;

}

char* time=getDateAndTime();

fprintf(fptr, "%s",time);

fprintf(fptr,"%s %d %d", hexa, oct, bin);

printf(" File saved");

fclose(fptr);

}

THIS IS MY CODE. Please help get the correct output. I need C language output

ConvertDec to_Hex-Oct-Bin.c is a simple conversion program that prompts the user for an integer from 1 to 1,000,000, and displays this integer value in hexadecimal, octal, and binary representation. The user is then asked if the output should be saved to a text file. If user replies in the affirmative, a name for the text file is requested. If the requested text file cannot be created, user is re-prompted for a different file name. The text file will contain user's name, current date, and output results (see example below). User Interface: Enter an Integer (1- 10 000000) or type x to exit: 240 Decimal: 240 Hexadecimal: FO Octal: 360 Binary: 11110000 Save to a file? (y): y Enter file name: cs222_hw3.txt File saved. Enter an Integer (1- 1000000) or typex to exit: x Good bye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions