
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- C Program for Program to find the area of a circle?
- C++ Program to calculate the volume and area of the Cylinder
- Java program to find the area of a circle
- Python Program to find the area of a circle
- Swift Program to Find the Area of a Circle
- Kotlin Program to Find the Area of a Circle
- Swift Program to calculate the volume and area of the Cylinder
- Golang program to calculate the volume and area of the Cylinder
- Haskell Program to calculate the volume and area of the Cylinder
- Python Program to calculate the volume and area of the Cylinder
- JavaScript program to find area of a circle
- C program to print area of triangle, square, circle, rectangle and polygon using switch case.
- Find the Area of a Circle in Java Program
- Program to find the Area of an Ellipse using C++
- Find the area of a circle in C programming.

Advertisements