1. Email Validation using Regex (C#)
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string email = "[email protected]"; // Change this to test
string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
Regex regex = new Regex(pattern);
if (regex.IsMatch(email))
{
Console.WriteLine("Valid Email");
}
else
{
Console.WriteLine("Invalid Email");
}
}
}
Explanation
2. Password Strength Checker (C#)
A strong password typically contains:
At least one uppercase letter
At least one lowercase letter
At least one digit
At least one special character
A minimum length of 8 characters
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string password = "StrongP@ssw0rd"; // Change this to test
if (IsStrongPassword(password))
{
Console.WriteLine("Strong Password");
}
else
{
Console.WriteLine("Weak Password");
}
}
public static bool IsStrongPassword(string password)
{
if (password.Length < 8)
return false;
bool hasUpperCase = Regex.IsMatch(password, @"[A-Z]");
bool hasLowerCase = Regex.IsMatch(password, @"[a-z]");
bool hasDigit = Regex.IsMatch(password, @"\d");
bool hasSpecialChar = Regex.IsMatch(password, @"[\W_]");
return hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar;
}
}
3. Find Day of the Week from Given Date (C#)
using System;
public class Program
{
public static void Main()
{
DateTime date = new DateTime(2025, 11, 06); // Change this to test
Console.WriteLine("Day of the Week: " + date.DayOfWeek);
}
}
Explanation
4. Compound Interest Calculation (C#)
Formula
[
A = P \left(1 + \frac{r}{n}\right)^{nt}
]
Where
( A ) is the amount of money accumulated after ( t ) years, including interest.
( P ) is the principal amount.
( r ) is the annual interest rate (decimal).
( n ) is the number of times that interest is compounded per year.
( t ) is the time the money is invested for, in years.
using System;
public class Program
{
public static void Main()
{
double principal = 1000; // Initial amount
double rate = 0.05; // 5% interest
int timesCompounded = 4; // Quarterly
int years = 5; // 5 years
double compoundInterest = CalculateCompoundInterest(principal, rate, timesCompounded, years);
Console.WriteLine($"Compound Interest: {compoundInterest:C}");
}
public static double CalculateCompoundInterest(double principal, double rate, int n, int t)
{
return principal * Math.Pow((1 + rate / n), n * t) - principal;
}
}
5. Simulate an ATM Transaction using Switch-Case (C#)
using System;
public class Program
{
static double balance = 10000; // Initial balance
public static void Main()
{
Console.WriteLine("Welcome to the ATM!");
Console.WriteLine("1. Check Balance");
Console.WriteLine("2. Deposit");
Console.WriteLine("3. Withdraw");
Console.WriteLine("4. Exit");
bool continueATM = true;
while (continueATM)
{
Console.Write("Select an option (1-4): ");
int option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Console.WriteLine($"Your balance is: {balance:C}");
break;
case 2:
Console.Write("Enter deposit amount: ");
double depositAmount = Convert.ToDouble(Console.ReadLine());
balance += depositAmount;
Console.WriteLine($"Deposited {depositAmount:C}. New balance: {balance:C}");
break;
case 3:
Console.Write("Enter withdrawal amount: ");
double withdrawalAmount = Convert.ToDouble(Console.ReadLine());
if (withdrawalAmount <= balance)
{
balance -= withdrawalAmount;
Console.WriteLine($"Withdrew {withdrawalAmount:C}. New balance: {balance:C}");
}
else
{
Console.WriteLine("Insufficient balance.");
}
break;
case 4:
Console.WriteLine("Thank you for using ATM!");
continueATM = false;
break;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}
}
Explanation
Simulates a basic ATM system with options for checking balance, depositing, withdrawing, and exiting.
JavaScript Versions
1. Email Validation using Regex (JavaScript)
function validateEmail(email) {
const pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return pattern.test(email);
}
console.log(validateEmail("[email protected]")); // true
console.log(validateEmail("invalid-email")); // false
2. Password Strength Checker (JavaScript)
function isStrongPassword(password) {
const patternUpperCase = /[A-Z]/;
const patternLowerCase = /[a-z]/;
const patternDigit = /\d/;
const patternSpecialChar = /[\W_]/;
return password.length >= 8 &&
patternUpperCase.test(password) &&
patternLowerCase.test(password) &&
patternDigit.test(password) &&
patternSpecialChar.test(password);
}
console.log(isStrongPassword("StrongP@ssw0rd")); // true
console.log(isStrongPassword("weakpassword")); // false
3. Find Day of the Week from Given Date (JavaScript)
function getDayOfWeek(dateString) {
const date = new Date(dateString);
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
return daysOfWeek[date.getDay()];
}
console.log(getDayOfWeek("2025-11-06")); // Thursday
4. Compound Interest Calculation (JavaScript)
function calculateCompoundInterest(principal, rate, n, t) {
return principal * Math.pow((1 + rate / n), n * t) - principal;
}
console.log(calculateCompoundInterest(1000, 0.05, 4, 5)); // Compound Interest
5. Simulate an ATM Transaction using Switch-Case (JavaScript)
let balance = 10000; // Initial balance
function atmTransaction() {
let continueATM = true;
while (continueATM) {
let option = prompt("Select an option: 1. Check Balance 2. Deposit 3. Withdraw 4. Exit");
switch (option) {
case "1":
alert("Your balance is: " + balance);
break;
case "2":
let depositAmount = parseFloat(prompt("Enter deposit amount:"));
balance += depositAmount;
alert("Deposited " + depositAmount + ". New balance: " + balance);
break;
case "3":
let withdrawalAmount = parseFloat(prompt("Enter withdrawal amount:"));
if (withdrawalAmount <= balance) {
balance -= withdrawalAmount;
alert("Withdrew " + withdrawalAmount + ". New balance: " + balance);
} else {
alert("Insufficient balance.");
}
break;
case "4":
alert("Thank you for using ATM!");
continueATM = false;
break;
default:
alert("Invalid option. Please try again.");
break;
}
}
}
atmTransaction();