3. Write a program to create a table of radius values and corresponding volumes
ID: 644129 • Letter: 3
Question
3. Write a program to create a table of radius values and corresponding volumes for a sphere. In function main prompt the user to enter the starting value of radius values (in centimeters), the increment between radius values and the final radius value in centimeters for the table. Call a function to print the table in a for loop, using the initial value, increment, and final value supplied by the user as function parameters. Include column headings. Use integer values for radii and doubles for volumes. Place radius values in the column on the left and volumes in the column on the right. Print the volumes with three decimal digits.
The formula for the volume of a sphere is . You may declare ? as a defined constant with the value of 3.14159.
Test with starting radius value of 5, increment of 5, and final value of 50 centimeters for the table.
Explanation / Answer
#include <iostream>
using namespace std;
void radical(int,int,int);
int main() {
int i,inc=5,end;
cout<<"start value for radious increment value by 5 and end value end value not more than 8 table is for 8";
cin>>i;
cin>>inc;
cin>>end;
radical(i,inc,end);
}
void radical(int i,int inc,int end)
{
int r[8];
const int pi=3.1459;
double vol[8];
int i1=0;
int radius;
r[0]=i;
for(i1=0;i1<end;i1++)
{
r[i]=r[i]+inc;
radius=r[i1]*r[i1]*r[i1];
}
for(i1=i;i1<end;i1=i1+inc)
{
radius=r[i1]*r[i1]*r[i1];
cout<<radius;
r[i]=r[i]+inc;
double c=4/3;
vol[i] =c* pi * radius;
}
for(i1=0;i1<end;i++)
{
/
cout<<"RADIOUS VOLUME";
//r(i1=0;i1<=end;i1++)
//
cout<<endl;
cout<<r[1];
cout<< " ";
cout<<vol[i];
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.