KEMBAR78
Write A Program To Print The Sum (Addition), Multiply, Subtract, Divide and Remainder of Two Numbers | PDF | Area | Computer Programming
0% found this document useful (0 votes)
32 views10 pages

Write A Program To Print The Sum (Addition), Multiply, Subtract, Divide and Remainder of Two Numbers

The document contains five C# programs demonstrating basic programming concepts. The programs cover arithmetic operations, calculating the area and perimeter of a rectangle, printing even numbers, generating a specific pattern, and handling a jagged array. Each program includes user input and outputs the results accordingly.
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)
32 views10 pages

Write A Program To Print The Sum (Addition), Multiply, Subtract, Divide and Remainder of Two Numbers

The document contains five C# programs demonstrating basic programming concepts. The programs cover arithmetic operations, calculating the area and perimeter of a rectangle, printing even numbers, generating a specific pattern, and handling a jagged array. Each program includes user input and outputs the results accordingly.
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
You are on page 1/ 10

1.

Write a program to print the sum (addition), multiply, subtract, divide and remainder of
two numbers.

namespace Assignment1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the first number: ");
int num1 = int.Parse(Console.ReadLine());

Console.WriteLine("Enter the second number: ");


int num2 = int.Parse(Console.ReadLine());

Console.WriteLine($"Sum: {num1 + num2}");


Console.WriteLine($"Multiply: {num1 * num2}");
Console.WriteLine($"Substract: {num1 - num2}");
Console.WriteLine($"divide: {num1 / num2}");
Console.WriteLine($"Remainder: {num1 % num2}");

Console.ReadKey();

}
}
}

2. Write a program to print the area and perimeter of a rectangle.

internal class Program


{
static void Main(string[] args)
{
Console.WriteLine("Enter the length of the rectangle: ");
double length = double.Parse(Console.ReadLine());

Console.WriteLine("Enter the width of the rectangle: ");


double width = double.Parse(Console.ReadLine());

double area = length * width;


double perimeter = 2 * (length + width);

Console.WriteLine($"Area: {area}");
Console.WriteLine($"Perimeter: {perimeter}");

Console.ReadKey();
}
}
3. Write a program to print all even numbers from 1 to n using for loop.
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number:");
int n = int.Parse(Console.ReadLine());

Console.WriteLine("Even numbers " + n);


for (int i = 2; i <= n; i += 2)
{
Console.WriteLine(i);
}

Console.ReadKey();
}
}

4. Write a program to print the following pattern using loop.


X0X0X0
0X0X0X
X0X0X0
0X0X0X
X0X0X0
internal class Program
{
static void Main(string[] args)
{
int rows = 5;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < 6; j++)
{
if ((i + j) % 2 == 0)
Console.Write("X");
else
Console.Write("0");
}
Console.WriteLine();
}

Console.ReadKey();
}
}
5. Write a program to take input for a jagged array and print using loop.

internal class Program


{
static void Main(string[] args)
{
Console.WriteLine("Enter the number of rows for the jagged array: ");
int rows = int.Parse(Console.ReadLine());
int[][] jaggedArray = new int[rows][];

for (int i = 0; i < rows; i++)


{
Console.WriteLine($"Enter the number of elements in row {i + 1}: ");
int elements = int.Parse(Console.ReadLine());
jaggedArray[i] = new int[elements];

for (int j = 0; j < elements; j++)


{
Console.Write($"Enter element [{i}][{j}]: ");
jaggedArray[i][j] = int.Parse(Console.ReadLine());
}
}

Console.WriteLine("The jagged array is:");


for (int i = 0; i < jaggedArray.Length; i++)
{
for (int j = 0; j < jaggedArray[i].Length; j++)
{
Console.Write(jaggedArray[i][j] + " ");
}
Console.WriteLine();
}
}
}

You might also like