C# Programming Experiments
Experiment 1: Check Whether the Entered Year is a Leap Year or Not
using System;
class LeapYearCheck {
static void Main() {
[Link]("Enter a Year: ");
int year = [Link]([Link]());
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
[Link]($"{year} is a Leap Year.");
else
[Link]($"{year} is not a Leap Year.");
}
// Input: 2024
// Output: 2024 is a Leap Year.
}
Experiment 2: Calculate Acceleration
using System;
class Acceleration {
static void Main() {
[Link]("Enter Initial Velocity (u): ");
double u = [Link]([Link]());
[Link]("Enter Final Velocity (v): ");
double v = [Link]([Link]());
[Link]("Enter Time (t): ");
double t = [Link]([Link]());
double a = (v - u) / t;
[Link]($"Acceleration: {a} m/s²");
}
// Input: u = 0, v = 20, t = 4
// Output: Acceleration: 5 m/s²
}
Experiment 3: Generate Random Numbers
using System;
class RandomNumbers {
static void Main() {
Random rnd = new Random();
[Link]("5 Random Numbers:");
for (int i = 0; i < 5; i++)
[Link]([Link](1, 101));
}
// Output: Random numbers between 1 and 100
}
Experiment 4: Use of Access Specifiers
using System;
class AccessSpecifiers {
private int privateVar = 1;
public int publicVar = 2;
protected int protectedVar = 3;
internal int internalVar = 4;
void Display() {
[Link]($"Private: {privateVar}, Public: {publicVar},
Protected: {protectedVar}, Internal: {internalVar}");
}
static void Main() {
AccessSpecifiers obj = new AccessSpecifiers();
[Link]();
}
// Output: All variables displayed since they are accessed within
the same class.
}