0% found this document useful (0 votes)
38 views7 pages

C# Console Applications for Math Calculations

The document contains 7 code examples that demonstrate taking user input, performing calculations, and outputting results. Each example shows how to: 1) Prompt the user for input and convert it to the appropriate data type; 2) Perform mathematical operations on the input values; and 3) Output the calculated results to the console. The examples cover topics like quadratic equations, area and perimeter calculations, payroll calculation, taxi fare calculation, and time conversion.

Uploaded by

minh tuan ta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views7 pages

C# Console Applications for Math Calculations

The document contains 7 code examples that demonstrate taking user input, performing calculations, and outputting results. Each example shows how to: 1) Prompt the user for input and convert it to the appropriate data type; 2) Perform mathematical operations on the input values; and 3) Output the calculated results to the console. The examples cover topics like quadratic equations, area and perimeter calculations, payroll calculation, taxi fare calculation, and time conversion.

Uploaded by

minh tuan ta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

class Program

{
static void Main()

{
Console.WriteLine("5x^2 - 5x +82 = ");
Console.WriteLine("Input your x");
int x = Convert.ToInt32(Console.ReadLine());
int sum = (5 * x * x) – (5 * x) + 82;
Console.WriteLine(sum);
}
}
class Program
{
static void Main()

{
Console.WriteLine("Input your length :"); int l =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input your width : "); int w =
Convert.ToInt32(Console.ReadLine());
int parameter = (l + w) * 2;
int area = l * w;
Console.WriteLine("Parameter : {0} Area : {1}", parameter, area);
}
}
class Program
{
static void Main()

{
Console.WriteLine("Input radius r = "); double r =
Convert.ToDouble(Console.ReadLine());
double area = r * r * 3.14;
double parameter = 2 * r * 3.14;
Console.WriteLine("Area of the circle = {0} Parameter of the circle = {1}",
area, parameter);
}
}
class Program
{
static void Main()

{
Console.WriteLine("Input your hour and minute "); int hour =
Convert.ToInt32(Console.ReadLine()); int minute = Convert.ToInt32(Console.ReadLine());
int second = hour * 60 * 60 + minute * 60;
Console.WriteLine("Total seconds : " + second);

}
}x`
class Program
{
static void Main()

{
Console.WriteLine("Input the number of month you have worked : ");int month =
Convert.ToInt32(Console.ReadLine());
double coef = 1;
if (month < 12) { coef = 1.92; }
else
{
if (month >= 12 & month < 36) { coef = 2.25; }
else
{
if (month >= 36 & month < 48) { coef = 3.54; }
else { if (month >= 48) { coef = 5; } }
}
}
double Salary = coef * 50;
Console.WriteLine("Payroll : {0}$", Salary);
}
}
static void Main()
{
Console.WriteLine("Input the amount of km you go on a taxi : "); double km1 =
Convert.ToDouble(Console.ReadLine());
double fare = 0;
double km2 = km1;
double km3 = 1;
if (km1 <= 1) { fare = 10; }
else { if (km1 > 1 & km1 <= 30) { km2 = km2 - 1; km3 = km2 / 0.2; fare = 10 +
Math.Floor(km3) * 2; }
else
{
if (km1 > 30) { km2 = km2 - 30; ; fare = 300 + Math.Floor(km2) * 6; }
}
}
Console.WriteLine("Payment : {0}", fare);

}
static void Main()
{
Console.WriteLine("Input a, b, c");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
double x1, x2;
double d = b * b - 4 * a * c;
if (a == 0) { x1 = (-c) / b; Console.WriteLine("x = {0}", x1); }
else
{
if (d < 0) { Console.WriteLine("Invalid"); }
else
{
if (d == 0) { x1 = x2 = (-b) / (2 * a); Console.WriteLine("x1 = x2 =
{0}", x1); }
else { if (d > 0) { x1 = (-b - Math.Sqrt(d)) / (2 * a); x2 = (-b +
Math.Sqrt(d)) / (2 * a); Console.WriteLine("x1 = {0} x2 = {1}", x1, x2); } }
}
}
}

You might also like