Question: The following C program named sum.c contains 8 errors (bugs), located in 8 different lines respectively: #include #define NO_OF_VALUES 5 int calculate_sum(int values[], int n)

  1. The following C program named sum.c contains 8 errors (bugs), located in 8 different lines respectively:
  1. #include
  2. #define NO_OF_VALUES 5
  3. int calculate_sum(int values[], int n)
  4. {
  5. int i;
  6. int sum == 0;
  7. for (i = 0; i < n; i--) {
  8. sum = sum + values[i];
  9. }
  10. return sum;
  11. }
  12. int main()
  13. {
  14. int n = 0;
  15. int input;
  16. int values[NUM_OF_VALUES];
  17. while (n > NUM_OF_VALUES);
  18. {
  19. printf("Please enter the values %c of %c ", n + 1, NUM_OF_VALUES);
  20. printf("(enter 0 to finish inputing values): ");
  21. scanf(" %i", &input);
  22. if (input = 0)
  23. {
  24. break; // exit the while loop
  25. else
  26. values[n] = input;
  27. }
  28. n++;
  29. }
  30. printf("The input values are: ");
  31. int i;
  32. for(i = 0; i < n; i++)
  33. {
  34. printf("%i ", values[i]);
  35. }
  36. printf(" ");
  37. char sum = calculate_sum(values, n);
  38. printf("The summation of these values is: %i ", sum);
  39. }

The following figure shows an example of the results when running the correct version of the above C program:

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!