Question: C programming QUESTION 2 [20 MARKS The two statements below explain two input functions defined in the stdio.h header file as written in the GNU

C programming
C programming QUESTION 2 [20 MARKS The two statements below explain two
input functions defined in the stdio.h header file as written in the
GNU C Library reference manual. Based on that, explain the advantage of

QUESTION 2 [20 MARKS The two statements below explain two input functions defined in the stdio.h header file as written in the GNU C Library reference manual. Based on that, explain the advantage of using scanf() function over getchar() function in reading character input(s). int scanf (const char *template, ...) int getchar (void) [4 Marks) (b) The program in Figure 1 is written to calculate and display equivalent resistance value based on connection type. Compiling the program however, results in at least five errors and warnings that causes the program to NOT work properly. Study and correct the code by highlighting the line numbers, explaining the error/warning and suggest correction, for EACH error/warning [16 Marks] 2. BE 1. #include float data (int); 3. 4. int main (void) { 5. float R, Req=0, more, count=1; 6. char connection; 7. printf("Please enter connection type. Enter 5 for series."); 8. scanf ("%c", connection); 9. if (connection S) { 10. do{ 11. R=data(count); 12. ++count; 13. Req Req + R; 14. printf("Do you have more resistors? Enter 1 for yes"); 15. scanf("%f", &more); 16. } while (more 1); 17. } 18. else{ 19. count = 3; 20. do{ 21. if (first == 1) { 22. first @; 23. Req=data(1); 24. R=data(2); 25. Req (Req*R)/(Req+R); 26. } 27. R=data(count); 28. ++count 29. Req (Req*R)/(Req+R); 30. printf("Do you have more resistors? Enter 1 for yes"); 31. scanf("%f", &more); 32. } while (more == 1); 33. } 34. printf("Total resistance: ", Req); 35. return ; 36. } 37. 38. float data (int count) { 39. float val; 40. printf ("Please enter Rd value> ", count); 41. scanf("%f", &val); 42. return val; 43. }

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!