Question: please solve me only question #2 parts e, f, and g... and thank you so much Question 1 Study the following program and answer the

please solve me only question #2 parts e, f, and g... and thank you so much
please solve me only question #2 parts e, f, and g... and
thank you so much Question 1 Study the following program and answer
the below questions Hint: you might rundt in Dev C++ before starting
answering the questions! #include int main(void) int number: char choice printf("Please enter
an integer number): scanf("%d". number: printinTo check whether the number is even
of odd. presse 'n") printf("To check whether the number is positive or
negative, press p in" printf"To check whether the number is multiple of

Question 1 Study the following program and answer the below questions Hint: you might rundt in Dev C++ before starting answering the questions! #include int main(void) int number: char choice printf("Please enter an integer number): scanf("%d". number: printinTo check whether the number is even of odd. presse 'n") printf("To check whether the number is positive or negative, press p in" printf"To check whether the number is multiple of 10, press m in" printPlease enter your choice scand".&choice); switch(choice) if (number2-0) printf is even w". number: 1 chic printed is odd w". number 1 break case care if (number): printf"%ld is positive number); 1 else if (number 01 printertid is negative 'n", number); 1 clse printed is zero! ". number: 1 break: case case 'M if (number10-0 printfind is a multiple of 10 number: 1 che printf("%ld is NOT a multiple of 10 w", numbety: 1 break; default print" ERROR: " is unrecognized option in choice return 0; 1 Page 1 of 7 a) What does this program do? Hint: Write a simple description for the tasks this program perform c. The program prompts the ser lo enter and it computer and prints b) Show a sample output for the program c) What will happen if we delete break statements that is shown at the end of case clauses. Hint: Run the program without break and see the caput. Look at the notes in Slide #40 of Lec-3. Page 2 of 7 d) Rewrite the program using if...else structure instead of switch-case statement Page 3 of 7 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 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! Page 6 of 7 Question #3: Write a program that asks the user to enter an integer number and checks whether the number is prime or not. Hint: A prime number (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37... ) is a natural number greater than that has no positive divisors other than I and itself. To check if a number Nis prime divide it in a loop from 2 to N-1 for remainder. If remainder is never 0, then N is prime. For example, 23 and 47 are prime, but 12 and 27 are not Question 4: Re-write the program of Question #3 using data files. The input data numbers. Exf contains (positive) integer numbers. Each time the program reads a number, check whether it is a prime and stores the result in the output file Results.txt 373 373 is Prime!! 11 11 is Prime!! 2552 2552 is NOT prime!! 5 is Prime!! 3561 3561 is NOT prime!! members.txt Result 5 End of Homework #2 Page 7 of 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!