Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question #2: The following program reads integer numbers from a file named numbers.tet. For each number, the program computes the reverse in order to check

image text in transcribed
image text in transcribed
image text in transcribed
Question #2: The following program reads integer numbers from a file named numbers.tet. For each number, the program computes the reverse in order to check whether the number is a palindrome number or not. It then reports the results into a file named Report.txt (A palindrome is any autor whose reverse is also some es. 1721.23432. 7.8 are palindromex hur 23489 mot) Suppose the file numbers.txt contains the following numbers: 373 11 2552 5 3561 numbers.txt Study the program carefully and answer the below questions Hint: you might run the program before starting answering the questions! e) Show the output of the program. Assume that the file anches.tot contains the stata shown above As the program contains nested while loop, determine how many times the following statements will be executed: Assame that the file mums.txt contains the data shown above 11 inlile = fopen("numbers.txt". -times) 2) printf("dis read from the filen. number: times 3) digtemp 10: times) 4) printf("%d is a palindrome number in number: times) g) How many times does the program check the condition of the outer while loop, i.c., status IEOF? Assume that the file here tot contains the data shown above times) Page 4 of 7 #include #include stdlib.h> int main(void) int number, reverse - 0, digt, temp: FILE infile.outfile: int status //open the input file and check if an error occurred infile = fopen("numbers.txt","7://open the input file iffinfile> NULL printf("Error: File numbers.txt" not foundin"); exit (1): > //open the output file and check if error occurred outfile = fopen("Report.txt","w foutfiles NULL printf("Error: File \"Report, bet\" can not be created in 1 status = fscanf(infile. ".&number): //read first number from the file whilestatus EOF //To read all the numbers in the file printf("%d is read from the file number); fprintf(outfile, "d", number): //compute the reverse of the number temp. number: reverse: while temp to digit temp X10 reverse reverse * 10digt: temp temp/10; printf("The reverse is: ", reverse): fprintf(outfile.80", reverse): //check whether the number is palindrome finumber == reverse printfd is a palindrome number ini", number fprintf(outfile." Palindrome "); 1 elsel printf"%d is not a palindrome numbert Win", number: fprintf(outfile. Non-Palindromen"); I/read another number from the file status = fscanf(infile. %d",&number): i/close the files fclose(infile: fclose(outfile: return 0; Page 5 of 7 a) What is the benefit of the statement temp = number for the program? What will happen if we eliminate it and use the variable number instead of temp in the inner while loop? Hint: Run the program with this modification and check the result! b) What is the purpose of the statement reverse = 0; in the program? What will happen if we didn't put it before the inner while loop? Hint: Run the program without this this statement and check the result

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

Discuss the steps of a generic change project.

Answered: 1 week ago

Question

LO2 Identify components of workflow analysis.

Answered: 1 week ago