Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question #1 The following program (in the next page) reads integer numbers from a file named numbers.txt. For each number, the program computes the reverse

image text in transcribed
image text in transcribed
Question #1 The following program (in the next page) reads integer numbers from a file named numbers.txt. 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 (4 palindrome is any number whose reverse is also same. eg. 1221.23432, 7, 8 are palindromes, but 23489 is not). Suppose the file numbers.txt contains the following numbers: 2542 13831 303 55 3324 numbers.txt Study the program carefully and answer the below questions: Hint: you might run the program before starting answering the questions! a) Show the output of the program. Assume that the file numbers.txt contains the data shown above #include #include int main(void) int number, reverse = 0, digit, temps FILE "infile, "outfile: int status //open the input file and check if an error occurred infile = fopen("numbers.txt'); //open the input file infile NULLY printf("Error: File\"numbers.txt not found!"); exit (1); //open the output file and check if error occurred outfile = fopen("Report.txt", "); iffoutfile NULLY printf("Error: File \"Report it can not be created a"); 1 status = fscanf(infile, "%d", &number): read first number from the file while status l-EOF //To read all the numbers in the file printf("%d is read from the file ", number): fprintf(outfile, "ad"number //compute the reverse of the number temp = number: reverse = 0; while(temp 1-0 digit temp%10: reverse reverse 10 digt; temp = temp/10, > printf("The reverse is: %d ", reverse fprintffoutfile, "d", reverse): // check whether the number is palindrome if(number reverse) printf("%d is a palindrome number nin", number: fprintf(outfile, "t Palindromein"); else! printf("%d is not a palindrome number lala", number fprintf(outfile, "t Non Palindrome //read another number from the file status = fscanffinfile, "%d", &number): //close the files fclose(infile): fclose(outfie) return 0

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions