Write a program in C-Sharp to evaluate an equation.

In C#, Console.WrilLine(""); is like printf() function in C. There are three syntax method a programmer can choose to display his result and they are,

Console.WriteLine("Hello, World"); //Normal Method.
//Below is the Concatenation Method.
Console.WriteLine(" The Sum Of "+a+" + "+b+" = "+c);
//Last Method.
Console.WriteLine("Sum Of {0} + {1} = {2}");

Let us now see, How to evaluate an expression like this,

( a + b ) * c
----------------
4 * d
using System;
using System.Collections.Generic;
using System.Text;

namespace prog1
{
class Program
{
static void Main(string[] args)
{
double a, b, c, d;
Console.Write("Enter the values for a: ");
a = double.Parse(Console.ReadLine());
Console.Write("Enter the values for b: ");
b = double.Parse(Console.ReadLine());
Console.Write("Enter the values for c: ");
c = double.Parse(Console.ReadLine());
Console.Write("Enter the values for d: ");
d = double.Parse(Console.ReadLine());
Console.WriteLine("The value of the expression is "+(((a+b)*c)/(4*d)));
Console.ReadLine();
}
}
}

Output:
Enter the values for a: 4
Enter the values for b: 5
Enter the values for c: 2
Enter the values for d: 4
The value of the expression is 1.125

0 comments:

Post a Comment

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.