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

Instruction: Write a C program called vol.c, that computes the volume of a spher

ID: 3637716 • Letter: I

Question

Instruction:

Write a C program called vol.c, that computes the volume of a sphere with a 10-meter radius,
using the formula v=4/3r3 . Declare as a float variable in the main function as follows:
float pi=3.14;
The value for r have be entered from the keyboard using scanf as in previous practical problem
Write the fraction 4/3 as (float)4/3

This is what I have:

#include<stdio.h>

int main (void)
{
float pi=3.14;
int r;

printf("Enter an integer: ");
scanf("%d",r);
volume = 4.0f/3.0f * pi * r * r * r;

printf("Volume (cubic units): %d ", volume);

return 0;
}

The code does not compile please provide explanation and answers on where I went wrong in my code above.

Explanation / Answer

please rate - thanks

you never declared volume. every variable must be declared before it can be used

#include<stdio.h>

int main (void)
{
float pi=3.14,volume;
int r;

printf("Enter an integer: ");
scanf("%d",r);
volume = 4.0f/3.0f * pi * r * r * r;

printf("Volume (cubic units): %d ", volume);

return 0;
}