C#1
C#1
using System;
class Program {
Console.WriteLine("HELLO INDIA");
Console.ReadLine();
using System;
class ArithmeticOperations {
int a = 10, b = 5;
Console.WriteLine("Addition:"+(a+b));
Console.WriteLine((a-b);
Console.WriteLine(a * b);
Console.WriteLine(a/b);
Console.ReadLine();
using System;
class LeapYearCheck {
static void Main() {
Console.WriteLine("Leap Year");
else
Console.ReadLine();
using System;
class StudentGrades {
string grade = marks >= 90 ? "A" : marks >= 80 ? "B" : marks >= 70 ? "C" : marks >= 60 ? "D" : "F";
Console.WriteLine(grade);
Console.ReadLine();
using System;
class FactorialProgram {
Console.WriteLine(fact);
Console.ReadLine();
using System;
class Program
{
static void Main()
{
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Table of " + i);
{
Console.WriteLine(i + " x " + j + " = " + i * j);
}
Console.WriteLine();
Console.ReadLine();
}
}
}
using System;
class Program
{
static void Main()
Console.WriteLine("String Operations");
Console.WriteLine("------------------");
// 1. Concatenation
// 2. Substring
// 3. IndexOf
// 4. LastIndexOf
// 8. ToUpper
// 9. ToLower
// 10. Contains
Console.ReadLine();
using System;
class Program
{
static void Main()
{
Console.WriteLine("Choose an option:");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
switch (choice)
{
case 1:
Console.Write("Enter first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter second number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Result: " + (num1 + num2));
break;
case 2:
Console.Write("Enter first number: ");
double num3 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter second number: ");
double num4 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Result: " + (num3 - num4)); // Corrected subtraction
break;
case 3:
Console.Write("Enter first number: ");
double num5 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter second number: ");
double num6 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Result: " + (num5 * num6));
break;
case 4:
Console.Write("Enter first number: ");
double num7 = Convert.ToDouble(Console.ReadLine()); // Fixed variable naming
Console.Write("Enter second number: ");
double num8 = Convert.ToDouble(Console.ReadLine()); // Fixed variable naming
if (num8 != 0)
{
Console.WriteLine("Result: " + (num7 / num8));
}
else
{
Console.WriteLine("Error: Division by zero is not allowed.");
}
break;
default:
Console.WriteLine("Invalid choice. Please choose a valid option.");
break;
}
Console.ReadLine(); // Keep the console open until the user presses Enter
}
}
using System;
class VariableDeclaration {
int a = 10;
float b = 10.5f;
double c = 20.55;
char d = 'A';
string e = "Hello";
Console.WriteLine($"Integer: {a}, Float: {b}, Double: {c}, Char: {d}, String: {e}");
using System;
class LargestNumber {
Console.WriteLine($"Largest: {largest}");
}
using System;
class Program
{
static void Main()
{
Console.Write("Enter the size of the array: ");
int n = Convert.ToInt32(Console.ReadLine());
using System;
class MinElementInArray {
int n = Convert.ToInt32(Console.ReadLine());
arr[i] = Convert.ToInt32(Console.ReadLine());
min = arr[i];
// 13. WCP to print the Fibonacci Series using Recursion for N Numbers.
using System;
class FibonacciSeries
{
static int Fibonacci(int n)
{
return (n <= 1) ? n : Fibonacci(n - 1) + Fibonacci(n - 2);
}
// Base Case: If n is 0 or 1, the function returns n directly.
//Recursive Case: The function calls itself with n-1 and n-2 and adds the
results.
// 14. WCP to find the smallest required number whose sum of digits equals N
using System;
class Program
{
static void Main()
{
Console.Write("Enter the number M (between 100 and 10000): ");
int M = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number N (less than 100): ");
int N = Convert.ToInt32(Console.ReadLine());
int number = M + 1;
while (true)
{
if (SumOfDigits(number) == N)
{
Console.WriteLine("The required number = " + number);
Console.WriteLine("Total number of digits = " + number.ToString().Length);
break;
}
number++;
}
}
class Program
{
static void Main()
{
Console.Write("Enter a number: ");
int number = Convert.ToInt32(Console.ReadLine());
if (IsDisariumNumber(number))
{
Console.WriteLine(number + " is a Disarium Number.");
}
else
{
Console.WriteLine(number + " is not a Disarium Number.");
Console.ReadLine();
}
}
int sum = 0;
for (int i = 0; i < numStr.Length; i++)
{
// This line calculates the power of the digit raised to the i + 1 power using the Math.Pow method.
The result is cast to an integer using the (int) cast and added to the sum variable
`
sum += (int)Math.Pow(digit, i + 1);
}
return sum == number;
}
using System;
class Program
if (squareStr.EndsWith(numStr))
else
/*A Smith Number is a composite number whose sum of digits is equal to the sum of the digits
of its prime factors (excluding 1).
For example:
666 → 6+6+6 = 18
o Prime factorization: 666 = 2 × 3 × 3 × 37
o Sum of digits of factors: 2+3+3+3+7 = 18 ✅ Smith Number
85 → 8+5 = 13
o Prime factorization: 85 = 5 × 17
o Sum of digits: 5+1+7 = 13 ✅ Smith Number
23 (Prime Number) ❌ Not a Smith Number */
using System;
class Program
if (IsPrime(num))
else
if (digitSum == factorSum)
else
}
Console.ReadLine(); // Keep console open
if (n % i == 0) return false;
return true;
int sum = 0;
while (n > 0)
sum += n % 10;
n /= 10;
}
return sum;
int sum = 0;
int original = n;
while (n % i == 0)
sum += GetDigitSum(i);
n /= i;
return sum;
using System;
class Program
if (sumOfDigits == num)
else
int sum = 0;
while (n > 0)
return sum;
/* An Emirp Number is a prime number that remains prime when its digits are reversed.
(Unlike palindromic primes, the reversed number must be different from the original.)
Examples:
using System;
class Program
{
static void Main()
{
Console.Write("Enter a number: ");
int num = Convert.ToInt32(Console.ReadLine());
if (IsPrime(num))
{
int reversedNum = ReverseNumber(num);
if (reversedNum != num && IsPrime(reversedNum))
Console.WriteLine($"{num} is an Emirp Number.");
else
Console.WriteLine($"{num} is NOT an Emirp Number.");
}
else
{
Console.WriteLine($"{num} is NOT an Emirp Number.");
}
//Q20.
using System;
class Program
Console.WriteLine("INVALID AMOUNT");
else
Console.Write("OUTPUT: ");
Console.WriteLine(ConvertToWords(amount));
Console.WriteLine("\nDENOMINATION:");
int totalNotes = 0;
totalNotes += count;
{
result += words[digit - '0'] + " ";
return result.Trim();