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

1.1) There are numerous opportunities for error in any program, many times in pl

ID: 3821113 • Letter: 1

Question

1.1) There are numerous opportunities for error in any program, many times in places that seem too simple to require close attention. What do you think the following program is supposed to do?

#include stdio.h

int main()
{
   double radius = 11; /* Centimeters
   double pi = 3.14159
   double sphere_volume = (4 / 3) * pi *(radius * radius * radius);
   double surface_area = 5 * pi * radius;
   printf("Volume = %.2f", sphere_volume);
   printf("Area = %.2f", surface_area);
   return 0;
}

1.2) Using Visual Studio:

Create a new empty Visual C++ Console Application project

Add a C source file (e.g., Source.c) to the project

Copy the code from Lab 1.1 into the source file.

Try compiling the program. What were the results? What error messages did you receive?

1.3) Fix the syntax errors in the program from Lab 1.1. What do you receive for output when you run the program?


1.4) The program from Lab 1.3 has two logic errors. Fix them both and show the corrected program.

NOTE: the correct formulas for a sphere's volume V and a sphere's surface area A area:

Explanation / Answer

Hi

I have fixed all compilation errors and highlghted the code changes below.

#include <stdio.h>

int main()
{
double radius = 11; // Centimeters
double pi = 3.14159;
double sphere_volume = (4 / 3) * pi *(radius * radius * radius);
double surface_area = 4 * pi * radius*radius;
printf("Volume = %.2f ", sphere_volume);
printf("Area = %.2f ", surface_area);
return 0;
}

Ouput:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Volume = 4181.46                                                                                                                                                                                                                                                       

Area = 1520.53

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote