Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Debug this program #include <stdio.h> #define NUM_TEMPS 10 main() { float temps[

ID: 3905881 • Letter: D

Question

Debug this program

#include <stdio.h>

#define NUM_TEMPS 10

main()

{

   float temps[NUM_TEMPS];

   int cr;

   temps[0] = 78.6; /* Subscripts ALWAYS begin at 0 */

   temps[1] = 82.1;

   temps[2] = 79.5;

   temps[3] = 75.0;

   temps[4] = 75.4;

   temps[5] = 71.8;

   temps[6] = 73.3;

   temps[7] = 69.5;

   temps[8] = 74.1;

   temps[9] = 75.7;

   /* Print the temps */

   printf("Daily temperatures for the last %m days: ", NUM_EMPS);

   for (ctr=0; ctr<NUM_TEMPS; ctr++)

      { printf("%.1f ", temps[ctr]); }

   return;

}

Explanation / Answer

The Errors in the Code Are ::

Here is the proper code:::


#include <stdio.h>

#define NUM_TEMPS 10

main()

{

float temps[NUM_TEMPS];

int cr;

temps[0] = 78.6; /* Subscripts ALWAYS begin at 0 */

temps[1] = 82.1;

temps[2] = 79.5;

temps[3] = 75.0;

temps[4] = 75.4;

temps[5] = 71.8;

temps[6] = 73.3;

temps[7] = 69.5;

temps[8] = 74.1;

temps[9] = 75.7;

/* Print the temps */

printf("Daily temperatures for the last %m days: ", NUM_TEMPS);

for (cr=0; cr<NUM_TEMPS; cr++)

{ printf("%.1f ", temps[cr]); }

return;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote