0% found this document useful (0 votes)
14 views4 pages

Job Name-1

The document explains the use of arithmetic and comparison operators in C#, showcasing how to perform basic mathematical calculations and comparisons between values. It includes example programs for performing arithmetic operations on two numbers, calculating properties of a circle, and finding the maximum of three numbers. The conclusion emphasizes the importance of these operators for effective programming in C#.

Uploaded by

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

Job Name-1

The document explains the use of arithmetic and comparison operators in C#, showcasing how to perform basic mathematical calculations and comparisons between values. It includes example programs for performing arithmetic operations on two numbers, calculating properties of a circle, and finding the maximum of three numbers. The conclusion emphasizes the importance of these operators for effective programming in C#.

Uploaded by

imransarker.web
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Job Name: Solve given problem using Arithmetic and comparison operator in C#.

Introduction: C# is a powerful, object-oriented programming language developed by Microsoft.


It is widely used for building applications ranging from desktop software to web applications. One
of the fundamental concepts in C# is performing arithmetic and comparison operations, which
we will explore in this report.

Arithmetic Operations in C#

Arithmetic operations allow us to perform basic mathematical calculations. The given C#


program takes two integer inputs from the user and performs five arithmetic operations:

Operator Description Example (a=10, b=3) Result


+ Addition a+b 13
- Subtraction a-b 7
* Multiplication a*b 30
/ Division a/b 3
% Modulus a%b 1

Comparison Operations in C#

Comparison operators are used to compare two values and return a boolean result (true or false).

Operator Description Example (a=10, b=3) Result

== Equal to a == b false

!= Not equal to a != b true

> Greater than a > b true

< Less than a < b false

>= Greater than or equal to a >= b true

<= Less than or equal to a <= b false

• Console.WriteLine() – Prints output to the console and moves the cursor to the next
line.
• Console.Write() – Prints output to the console without moving to the next line.
• Console.ReadLine() – Reads an entire line of input from the user as a string.
• Console.Read() – Reads a single character from the input as an integer (ASCII value).
• Convert.ToInt32() – Converts a value (e.g., string, double) to a 32-bit integer.

1. Write a C# Console program to input two numbers and perform all arithmetic operations.

Input:
First number:
10
Second number:
5
Output:
Sum = 15
Difference = 5
Product = 50
Quotient = 2
Modulus = 0
Code:
int a, b, sum, diff, product, qoutient, mod;
Console.WriteLine("Input: ");
Console.WriteLine("First Number: ");

a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Second Number: ");
b = Convert.ToInt32(Console.ReadLine());

sum = a + b;
diff = a - b;
product = a * b;
qoutient = a / b;
mod = a % b;

Console.WriteLine("Output: ");
Console.WriteLine("Sum = " + sum);
Console.WriteLine($"Difference = {diff}");
Console.WriteLine($"Product = { product}");
Console.WriteLine($"Quotient = {qoutient}");
Console.WriteLine($"Modulus = {mod}");

Output:
2. Write a C# Console program to input radius of a circle from user and find diameter,
circumference and area of the circle.
Input:
Enter radius: 10
Output:
Diameter = 20 units
Circumference = 62.79 units
Area = 314 sq. units

Code:
const double PI = 3.1416;
int radius;
double diameter, circumference, area ;
Console.WriteLine("Input: ");
Console.Write("Enter Radius: ");
radius = Convert.ToInt32(Console.ReadLine());

diameter = 2 * radius;
circumference = 2 * radius * PI;
area = PI * radius * radius;

Console.WriteLine("Output: ");
Console.WriteLine($"Diameter = {diameter} units");
Console.WriteLine($"Circumference = {circumference} units");
Console.WriteLine($"Area = {area} units");

Output:
3. Write a C# Console program to find maximum between three numbers.
Input:
Input num1: 10
Input num2: 20
Input num3: 15
Output:
Maximum is: 20
Code:
int a, b, c;
Console.WriteLine("Input: ");
Console.Write("Input num1: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Input num2: ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Input num3: ");
c = Convert.ToInt32(Console.ReadLine());

int max = (a>b && b>c) ? a :(b>c) ? b :c;


Console.WriteLine("Output: ");
Console.WriteLine($"Maximum is: {max}");

Output:

Conclusion:
This program demonstrates how to use arithmetic and comparison operators in C#. Arithmetic
operations help perform calculations, while comparison operators are essential for decision-
making in programs. These concepts are fundamental for writing effective C# applications, such
as calculators and automated decision-making systems.

You might also like