Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Calculate Area for Rectangle, Square, Triangle, Circle in C#
WhatsApp
Ujjwal Patel
Jan 14
2015
95.4
k
0
0
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
ConsoleApplication1
{
class
CalcAvgPerc
//Calculate the Average marks and percentage for students
{
public
float
length, breadth, radius, side, hieght, breadthfortriangle;
static
void
Main(
string
[] args)
{
CalcAvgPerc a =
new
CalcAvgPerc();
a.Rectangle();
a.Circle();
a.Square();
a.Triangle();
Console.ReadKey();
}
public
void
Rectangle()
{
Console.WriteLine(
"Enter the Length for Rectangle"
);
length =
float
.Parse(Console.ReadLine());
Console.WriteLine(
"Enter the breadth for Rectangle"
);
breadth =
float
.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(
"Area of rectangle is :{0}"
, length * breadth);
}
public
void
Circle()
{
Console.WriteLine(
"Enter the Radius of the Circle"
);
radius =
float
.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(
"Area of Circle is:{0}"
, 3.14 * radius * radius);
}
public
void
Square()
{
Console.WriteLine(
"Enter the side of a square"
);
side =
float
.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(
"Area of Square is:{0}"
, side * side);
}
public
void
Triangle()
{
Console.WriteLine(
"Enter the Breadth for Triangle "
);
breadthfortriangle =
float
.Parse(Console.ReadLine());
Console.WriteLine(
"Enter the Hieght for Triangle "
);
hieght =
float
.Parse(Console.ReadLine());
System.Threading.Thread.Sleep(2000);
Console.WriteLine(
"Area of Triangle is:{0}"
, (breadthfortriangle * hieght) / 2);
}
}
}
C#
Area for Rectangle
Calculate Area
Up Next
Calculate Area for Rectangle, Square, Triangle, Circle in C#