#2 | C++ | Write a Program to Calculate Area of a circle.
CompTech
C++ Practical Assignment
#practical 2
YouTube Video :-
Question :-
Write a Program to calculate area of a Circle in C++.
Code :-
// Write a Program to Find Area of a circle
// Area = pi(3.14) * r * r
// r = Radius of a circle
#include<iostream>
using namespace std;
int main()
{
// declare some variables
int r;
float pi=3.14, area;
// assign values from user
cout<<"Enter radius of a Circle :- ";
cin>>r;
// calculate the area of circle
area = (float) pi * r * r;
// print area of a circle
cout<<"\n-> Area of a Circle = "<<area;
}
Description :-
- First we have to declare three variables to store the data..
1. integer r for storing the value of radius
2. float pi for pi(3.17)
3. float area to store the result after calculation
- After declaring variables we have to assign the value to the Integer variable 'r' from user.
- Then we have to calculate the area by using the formula.
- formula = pi * r *r
- After calculation, we have the area of circle in our float variable area.
- we simply print the variable float for displaying the result.
Comments
Post a Comment