![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to find the area of circle and cylinder using structures.
In C programming language, we can find the area of circle, area and volume of cylinder with the help of structures.
- The logic used to find area of circle is as follows −
s.areacircle = (float)pi*s.radius*s.radius;
- The logic used to find area of cylinder is as follows −
s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle;
- The logic used to find the volume of cylinder is −
s.volumecylinder = s.areacircle*s.line;
Algorithm
Refer an algorithm given below to find the area of circle and cylinder along with other parameters by using structures.
Step 1 − Declare structure members.
Step 2 − Declare and initialize the input variables.
Step 3 − Enter length and radius of cylinder.
Step 4 − Compute area of circle.
Step 5 − Compute area of cylinder.
Step 6 − Compute volume of cylinder.
Example
Following is the C program to find the area of circle and cylinder along with other parameters by using structures −
#include<stdio.h> struct shape{ float line; float radius; float areacircle; float areacylinder; float volumecylinder; }; int main(){ struct shape s; float pi = 3.14; //taking the input from user printf("Enter a length of line or height : "); scanf("%f",&s.line); printf("Enter a length of radius : "); scanf("%f",&s.radius); //area of circle s.areacircle = (float)pi*s.radius*s.radius; printf("Area of circular cross-section of cylinder : %.2f
",s.areacircle); //area of cylinder s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle; printf("Surface area of cylinder : %.2f
", s.areacylinder); //volume of cylinder s.volumecylinder = s.areacircle*s.line; printf("volume of cylinder : %.2f
", s.volumecylinder); return 0; }
Output
When the above program is executed, it produces the following output −
Enter a length of line or height: 34 Enter a length of radius: 2 Area of circular cross-section of cylinder: 12.56 Surface area of cylinder: 452.16 volume of cylinder : 427.04
Advertisements