S.No.
List of Programs Date Signature
1 Print “Hello World” 13/2/25
2 Print your name by taking user input 27/2/25
3 Addition of two no.s 4/3/25
4 Maximum of two no.s 6/3/25
5 Sum of digits of a no. 19/3/25
6 Sum of first n natural no.s 20/3/25
7 Check even or odd using ternary 21/3/25
operator
8 Implement Boxing and unboxing 27/3/25
9 Check input alphabet as vowel using 28/3/25
switch case
10 Implement method overloading 4/4/25
1. WAP to print ‘Hello World’ in C#.
PROGRAM:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
OUTPUT:
Hello World!
2. WAP to take input & print your Name.
PROGRAM:
using System;
namespace Name
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter username:");
string userName = Console.ReadLine();
Console.WriteLine("Username is: " + userName);
}
}
}
OUTPUT:
Enter username: Rahul
Username is: Rahul
3. WAP to add two numbers with user input.
PROGRAM:
using System;
namespace addition
{
class Program
{
static void Main(string[] args)
{
int num1, num2, sum;
Console.WriteLine("Enter the first number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number: ");
num2 = Convert.ToInt32(Console.ReadLine());
sum = num1 + num2;
Console.WriteLine("The sum of " + num1 + " and " + num2 + " is: "
+ sum);
}
}
}
OUTPUT:
Enter the first number: 10
Enter the second number: 20
The sum of 10 and 20 is: 30
4. WAP to find the maximum of two numbers.
PROGRAM:
using System;
namespace maximum
{
class Program
{
static void Main(string[] args)
{
int num1 = 50;
int num2 = 90;
int maxNum;
Console.WriteLine("Number 1: "+num1);
Console.WriteLine("Number 2:
"+num2); if (num1 > num2) {
maxNum = num1;
} else {
maxNum = num2;
}
Console.WriteLine("Maximum number is: "+maxNum);
}
}
}
OUTPUT:
Number 1: 50
Number 2: 90
Maximum number is: 90
5. WAP to calculate the sum of digits of a number.
PROGRAM:
using System;
namespace Digits
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the Number : ");
int number = int.Parse(Console.ReadLine());
int sum = 0, reminder;
while (number > 0)
{
reminder = number % 10;
sum = sum + remainder;
number = number / 10;
}
Console.WriteLine("The Sum of Digits is:” + sum);
}
}
}
OUTPUT:
Enter the Number : 523
The Sum of Digits is: 10
6. WAP to compute the sum of first n natural numbers.
PROGRAM:
using System;
namespace Loop
{
class Program
{
static void Main(string[] args)
{
int n = 5, sum = 0;
for (int i=1; i<=n; i++)
{
sum += i;
}
Console.WriteLine("Sum of first”+ n + “natural numbers is:”+sum);
}
}
}
OUTPUT:
Sum of first 5 natural numbers: 15
7. WAP to check if the number is odd or even using ternary
operator.
PROGRAM:
using System;
namespace Conditional
{
class Ternary
{
public static void Main(string[] args)
{
int number = 10;
bool isEven;
isEven = (number % 2 == 0) ? true : false ;
Console.WriteLine(isEven);
}
}
}
OUTPUT:
True
8. WAP to demonstrate Boxing & Unboxing in C#.
PROGRAM:
using System;
namespace Program
{
class Boxing
{
public static void Main(string[] args)
{
int n = 357;
object box = n;
Console.WriteLine("Boxed value: " + box);
int unbox = (int)box;
Console.WriteLine("Unboxed value: " + unbox);
}
}
}
OUTPUT:
Boxed value: 357
Unboxed value: 357
9. WAP to check if the input alphabet is a vowel or not using switch case.
PROGRAM:
using System;
namespace Conditional
{
class SwitchCase
{
public static void Main(string[] args)
{
char ch;
Console.WriteLine("Enter an alphabet");
ch = Convert.ToChar(Console.ReadLine());
switch(Char.ToLower(ch))
{
case 'a':
Console.WriteLine("Vowel");
break;
case 'e':
Console.WriteLine("Vowel");
break;
case 'i':
Console.WriteLine("Vowel");
break;
case 'o':
Console.WriteLine("Vowel");
break;
case 'u':
Console.WriteLine("Vowel");
break;
default:
Console.WriteLine("Not a
vowel"); break;
}
}
}
}
OUTPUT:
Enter an alphabet
X
Not a vowel
10.WAP to implement method overloading in C#.
PROGRAM:
using System;
namespace MethodOverload
{ class Program {
void display(int a) {
Console.WriteLine("Arguments: " + a);
}
void display(int a, int b) {
Console.WriteLine("Arguments: " + a + " and " + b);
}
static void Main(string[] args)
{ Program p1 = new
Program(); p1.display(100);
p1.display(100, 200);
Console.ReadLine();
}
}
}
OUTPUT:
Arguments: 100
Arguments: 100 and 200