
- Swift Tutorial
- Swift - Home
- Swift - Overview
- Swift - Environment
- Swift - Basic Syntax
- Swift - Data Types
- Swift - Variables
- Swift - Optionals
- Swift - Tuples
- Swift - Constants
- Swift - Literals
- Swift - Operators
- Swift - Decision Making
- Swift - Loops
- Swift - Strings
- Swift - Characters
- Swift - Arrays
- Swift - Sets
- Swift - Dictionaries
- Swift - Functions
- Swift - Closures
- Swift - Enumerations
- Swift - Structures
- Swift - Classes
- Swift - Properties
- Swift - Methods
- Swift - Subscripts
- Swift - Inheritance
- Swift - Initialization
- Swift - Deinitialization
- Swift - ARC Overview
- Swift - Optional Chaining
- Swift - Type Casting
- Swift - Extensions
- Swift - Protocols
- Swift - Generics
- Swift - Access Control
- Swift Useful Resources
- Swift - Compile Online
- Swift - Quick Guide
- Swift - Useful Resources
- Swift - Discussion
Swift Program to Calculate Area of Circle Inscribed in Square
This tutorial will discuss how to write swift program to calculate area of circle inscribed in square.
We have a figure in which a circle is inscribed in a square. Which means the centre of the circle and the square is same and the diameter of the circle is equal to the length of the side of the square. If we have at least one measurement of square or the circle, then we can easily calculate the area and perimeter of the square, or area and circumference and area of the circle.
Here we find the area of the circle inscribe in the square using the following formula −
(丌/4)*q*q
Here, q is the radius of the circle and side of the square.
Derivation of the above Formula:
Suppose q is the side of the square
Area of the circle is 丌r2.
As we known that the side and the diameter of the circle is equal. So, the radius is −
r = q/2
Hence the area of the circle inscribed in square is −
A = 丌(q/2)2 = (丌/4)q2
Below is a demonstration of the same −
Input
Suppose our given input is −
side = 15
Output
The desired output would be −
Area of the circle inscribed in square = 176.71458676442586
Algorithm
Following is the algorithm −
Step 1 - Create a function with return value.
Step 2 - Find the area of the circle inscribe in square using the following formula:
return (Double.pi/4) * q * q
Step 3 - Calling the function and pass the side in the circle as a parameter.
Step 4 - Print the output.
Example
The following program shows how to calculate the area of circle inscribed in square.
import Foundation import Glibc // Creating a function to find the area of // circle inscribed in square func inscribedCircleArea(q:Double) -> Double{ return (Double.pi/4) * q * q } var num = 10.0 print("Side of the square is", num) print("Area of the circle inscribe in square:", inscribedCircleArea(q:num))
Output
Side of the square is 10 Area of the circle inscribe in square: 78.53981633974483
Here, in the above program we create a function which return the area of the circle inscribe in the square using the following formula −
return (Double.pi/4) * q * q
Here, Double.pi is used to access predefined pi value.
- Related Articles
- Program to calculate the area of an Circle inscribed in a Square
- Area of a square inscribed in a circle which is inscribed in a hexagon in C Program?
- C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?
- Find the Area of a Circle Inscribed in a Square in Java
- Area of circle inscribed within rhombus in C Program?
- Swift Program to Find Area of Square
- Area of decagon inscribed within the circle in C Program?
- Swift Program to Calculate Area of Octagon
- Swift Program to Calculate Area of Hexagon
- Swift Program to Calculate Area of Pentagon
- Area of circle inscribed within rhombus?
- C Program for area of decagon inscribed within the circle?
- Swift Program to calculate the area of Cube
