150k views
5 votes
Write a program that takes the radius of a sphere (a floating-point number) as input and then outputs the sphere’s: Diameter (2 × radius) Circumference (diameter × π) Surface area (4 × π × radius × radius) Volume (4/3 × π × radius × radius × radius)

User Fdireito
by
7.8k points

2 Answers

2 votes

Final answer:

To calculate the properties of a sphere, such as diameter, circumference, surface area, and volume, we can use a Python program that takes the radius as input and applies mathematical formulae for a sphere.

Step-by-step explanation:

To create a program that calculates the properties of a sphere, we will use the following formulae for a sphere: diameter is 2 × radius, circumference is diameter × π (pi), surface area is 4 × π × radius², and volume is (4/3) × π × radius³.


Example Code in Python

Here is a simple Python program for calculating the properties of a sphere:

import math
# Input: radius of a sphere
def sphere_properties(radius):
diameter = 2 * radius
circumference = diameter * math.pi
surface_area = 4 * math.pi * radius ** 2
volume = (4/3) * math.pi * radius ** 3
return diameter, circumference, surface_area, volume

# Example usage:
radius = float(input("Enter the radius of the sphere: "))
properties = sphere_properties(radius)
print(f"Diameter: {properties[0]}")
print(f"Circumference: {properties[1]}")
print(f"Surface Area: {properties[2]}")
print(f"Volume: {properties[3]}")

This program prompts the user to input the radius as a floating-point number, and then outputs the calculated diameter, circumference, surface area, and volume of the sphere.

User Con
by
8.0k points
3 votes

Answer:

#include<iostream>

using namespace std;

int main(){

float radius;

cout<<"Enter the radius of the sphere: ";

cin>>radius;

float diameter = 2*radius;

float circumference = diameter * 3.14;

float surface_area = 4*3.14*radius*radius;

float volume = (4/3)*3.14*radius*radius*radius;

cout<<"The diameter is: "<<diameter<<endl;

cout<<"The circumference is: "<<circumference<<endl;

cout<<"The surface area is: "<<surface_area<<endl;

cout<<"The volume is: "<<volume<<endl;

}

Step-by-step explanation:

First include the library iostream for input/output in c++ programming.

then, create the main function and declare the variable radius as floating type.

Use cout to print the message on the screen.

Use cin to store the value in the variable.

After that, write the formula to calculate the values and store the results in the variables.

and finally print the result with message.

User Jinesh
by
7.5k points

No related questions found