21. Write a program to find the average of numbers in a hardcoded array.
Required Input:
Array: [10, 20, 30, 40, 50]
Expected Output:
Average: 30
Code In C#
using System;
class AverageArray
{
static void Main()
{
// Calculate the average of array elements
}
}
Run Code?
Click Run Button to view compiled output
22. Create a program to find whether a hardcoded number is a prime number.
Required Input:
Number: 17
Expected Output:
Is Prime: True
Code In C#
using System;
class PrimeCheck
{
static void Main()
{
// Check if the number is prime
}
}
Run Code?
Click Run Button to view compiled output
23. Write a program to find all prime numbers between two hardcoded numbers.
Required Input:
Range: 10 to 20
Expected Output:
Prime Numbers: 11 13 17 19
Code In C#
using System;
class PrimeInRange
{
static void Main()
{
// Find all prime numbers in the given range
}
}
Run Code?
Click Run Button to view compiled output
24. Create a program to print all the odd numbers between 1 and a hardcoded number.
Required Input:
Number: 10
Expected Output:
Odd Numbers: 1 3 5 7 9
Code In C#
using System;
class PrintOddNumbers
{
static void Main()
{
// Print all odd numbers up to the given number
}
}
Run Code?
Click Run Button to view compiled output
25. Write a program to check if a hardcoded number is a perfect square.
Required Input:
Number: 16
Expected Output:
Is Perfect Square: True
Code In C#
using System;
class PerfectSquareCheck
{
static void Main()
{
// Check if the number is a perfect square
}
}
Run Code?
Click Run Button to view compiled output
26. Create a program to find the sum of digits of a hardcoded number.
Required Input:
Number: 123
Expected Output:
Sum of Digits: 6
Code In C#
using System;
class SumOfDigits
{
static void Main()
{
// Find the sum of digits of the number
}
}
Run Code?
Click Run Button to view compiled output
27. Write a program to calculate the power of a number using recursion.
Required Input:
Base: 2, Exponent: 3
Expected Output:
Result: 8
Code In C#
using System;
class PowerCalculation
{
static void Main()
{
// Calculate power using recursion
}
}
Run Code?
Click Run Button to view compiled output
28. Create a program to find the reverse of a hardcoded number.
Required Input:
Number: 1234
Expected Output:
Reversed Number: 4321
Code In C#
using System;
class ReverseNumber
{
static void Main()
{
// Reverse the digits of the number
}
}
Run Code?
Click Run Button to view compiled output
29. Write a program to find the second largest number in a hardcoded array.
Required Input:
Array: [10, 20, 15, 5, 30]
Expected Output:
Second Largest: 20
Code In C#
using System;
class SecondLargest
{
static void Main()
{
// Find the second largest number in the array
}
}
Run Code?
Click Run Button to view compiled output
30. Create a program to print all the distinct elements in a hardcoded array.
Required Input:
Array: [1, 2, 2, 3, 4, 4, 5]
Expected Output:
Distinct Elements: 1, 2, 3, 4, 5
Code In C#
using System;
using System.Collections.Generic;
class DistinctElements
{
static void Main()
{
// Print distinct elements in the array
}
}
Run Code?
Click Run Button to view compiled output