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

C# Programs Lab3

The document contains code for 4 different C# programs. Program 1 takes in two numbers, performs addition, subtraction, multiplication and division based on a user's selection. Program 2 checks if a string is a palindrome. Program 3 checks if a number is even or odd. Program 4 checks if a number is prime or not.
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)
15 views4 pages

C# Programs Lab3

The document contains code for 4 different C# programs. Program 1 takes in two numbers, performs addition, subtraction, multiplication and division based on a user's selection. Program 2 checks if a string is a palindrome. Program 3 checks if a number is even or odd. Program 4 checks if a number is prime or not.
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

Program 1

/*
* C# Program to Perform all Basic Arithmetic Operations
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int Num1, Num2, result;
char option;
Console.Write("Enter the First Number : ");
Num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Second Number : ");
Num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Main Menu");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
Console.Write("Enter the Operation you want to perform : ");
option = Convert.ToChar(Console.ReadLine());
switch (option)
{
case '1':
result = Num1 + Num2;
Console.WriteLine("The result of Addition is : {0}", result);
break;
case '2':
result = Num1 - Num2;
Console.WriteLine("The result of Subtraction is : {0}",
result);
break;
case '3':
result = Num1 * Num2;
Console.WriteLine("The result of Multiplication is : {0}",
result);
break;
case '4':
result = Num1 / Num2;
Console.WriteLine("The result of Division is : {0}", result);
break;
default:
Console.WriteLine("Invalid Option");
break;
}
Console.ReadLine();
}

}
}
Program 2

Program to find whether string is Palindrome or not

Program 3

/*
* C# Program to Check whether the Entered Number is Even or Odd
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace check1
{
class Program
{
static void Main(string[] args)
{
int i;
Console.Write("Enter a Number : ");
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.Write("Entered Number is an Even Number");
Console.Read();
}
else
{
Console.Write("Entered Number is an Odd Number");
Console.Read();
}
}
}
}

Program 4

Program to find number is prime or not

using System;
namespace Demo
{
class MyApplication
{
public static void Main()
{
int n = 5, a = 0;
for (int i = 1; i <= n; i++)
{
if (n % i == 0) {
a++;
}
}
if (a == 2)
{
Console.WriteLine("{0} is a Prime Number", n);
}
else
{
Console.WriteLine("Not a Prime Number");
}
Console.ReadLine();
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy