TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Calculate Area for Rectangle, Square, Triangle, Circle in C#
Ujjwal Patel
Jan 14
2015
Code
93.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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