compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an "invalid choice error" for other values.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an "invalid choice error" for other values.

Expert Solution
Step 1

NOTE:--since programming language is not specified  so we are providing solution in c programming.

Step 2

#SOURCECODE

#include<stdio.h>
void main()
{
float sa,ta,vol,h,r,pi=3.14;
int n;

printf("enter the radius:");
scanf("%f",&r);

printf("enter the height:");
scanf("%f",&h);
printf("\nenter 1 for cylinder\nenter 2 for sphere");
printf("\nenter choice:");
scanf("%d",&n);

switch (n)
{
case 1:
sa=2*pi*r*h;
ta=sa+(2*pi*r*r);
vol=pi*r*r*h;
printf("side area of cylinder=%f",sa);
printf("\ntotal area of cylinder=%f",ta);
printf("\nvolume of cylinder=%f",vol);
break;
case 2:
sa=4*pi*r*r;
vol=(4/3)*pi*r*r*h;
printf("area of sphere%f",sa);
printf("\nvolume of sphere%f",vol);
break;
default:
printf("invalid choice error");
break;
}

}

OUTPUT:--

enter the radius:2.1
enter the hieght:5.0

enter 1 for cylinder
enter 2 for sphere

enter choice:1
side area of cylinder=65.940002
total area of cylinder=93.634796
volume of cylinder=69.236992

 

enter the radius:2.2
enter the hieght:3.5

enter 1 for cylinder
enter 2 for sphere
enter choice:2
area of sphere60.790405
volume of sphere53.191605

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education