
Practice 70 C# Function Programming Questions
Q1. Write a C# program to find the factorial of a number using a function.
Input: Number = 5
Output: Factorial = 120
Q2. Write a C# program to check whether a number is prime using a function.
Input: Number = 7
Output: Prime
Q3. Write a C# program to find the sum of two numbers using a function.
Input: Number1 = 10, Number2 = 20
Output: Sum = 30
Q4. Write a C# program to calculate the power of a number using a function.
Input: Base = 2, Exponent = 3
Output: Power = 8
Q5. Write a C# program to find the maximum of two numbers using a function.
Input: Number1 = 10, Number2 = 20
Output: Maximum = 20
Q6. Write a C# program to calculate the area of a rectangle using a function.
Input: Length = 5, Width = 10
Output: Area = 50
Q7. Write a C# program to calculate the area of a circle using a function.
Input: Radius = 7
Output: Area = 153.94
Q8. Write a C# program to check if a number is even or odd using a function.
Input: Number = 4
Output: Even
Q9. Write a C# program to find the square of a number using a function.
Input: Number = 5
Output: Square = 25
Q10. Write a C# program to calculate the sum of digits of a number using a function.
Input: Number = 123
Output: Sum of digits = 6
Q11. Write a C# program to reverse a string using a function.
Input: String = "Hello"
Output: String = "olleH"
Q12. Write a C# program to find the length of a string using a function.
Input: String = "Hello World"
Output: Length = 11
Q13. Write a C# program to check if a string is a palindrome using a function.
Input: String = "madam"
Output: Palindrome
Q14. Write a C# program to concatenate two strings using a function.
Input: String1 = "Hello", String2 = "World"
Output: HelloWorld
Q15. Write a C# program to calculate the area of a triangle using a function.
Input: Base = 6, Height = 8
Output: Area = 24
Q16. Write a C# program to find the factorial of a number using recursion.
Input: Number = 4
Output: Factorial = 24
Q17. Write a C# program to count the number of vowels in a string using a function.
Input: String = "Hello World"
Output: Vowel Count = 3
Q18. Write a C# program to calculate the circumference of a circle using a function.
Input: Radius = 5
Output: Circumference = 31.42
Q19. Write a C# program to find the greatest of three numbers using a function.
Input: Number1 = 10, Number2 = 20, Number3 = 30
Output: Greatest = 30
Q20. Write a C# program to convert Celsius to Fahrenheit using a function.
Input: Celsius = 25
Output: Fahrenheit = 77
Q21. Write a C# program to convert Fahrenheit to Celsius using a function.
Input: Fahrenheit = 77
Output: Celsius = 25
Q22. Write a C# program to find the largest number in an array using a function.
Input: Array = [10, 20, 30, 40]
Output: Largest = 40
Q23. Write a C# program to find the smallest number in an array using a function.
Input: Array = [10, 20, 5, 40]
Output: Smallest = 5
Q24. Write a C# program to find the average of numbers in an array using a function.
Input: Array = [10, 20, 30]
Output: Average = 20
Q25. Write a C# program to convert a string to uppercase using a function.
Input: String = "hello"
Output: HELLO
Q26. Write a C# program to convert a string to lowercase using a function.
Input: String = "HELLO"
Output: hello
Q27. Write a C# program to find the sum of even numbers in an array using a function.
Input: Array = [1, 2, 3, 4, 5]
Output: Sum = 6
Q28. Write a C# program to find the sum of odd numbers in an array using a function.
Input: Array = [1, 2, 3, 4, 5]
Output: Sum = 9
Q29. Write a C# program to find the second largest number in an array using a function.
Input: Array = [10, 20, 30, 40]
Output: Second Largest = 30
Q30. Write a C# program to remove a character from a string using a function.
Input: String = "Hello", Character = 'l'
Output: Heo
Q31. Write a C# program to find the number of occurrences of a character in a string using a function.
Input: String = "Hello", Character = 'l'
Output: Occurrences = 2
Q32. Write a C# program to check whether a number is a perfect square using a function.
Input: Number = 16
Output: Perfect square
Q33. Write a C# program to check whether a number is a perfect number using a function.
Input: Number = 28
Output: Perfect number
Q34. Write a C# program to find the ASCII value of a character using a function.
Input: Character = 'A'
Output: ASCII value = 65
Q35. Write a C# program to calculate the area of a square using a function.
Input: Side = 4
Output: Area = 16
Q36. Write a C# program to check whether a year is a leap year using a function.
Input: Year = 2024
Output: Leap Year
Q37. Write a C# program to find the sum of elements in an array using a function.
Input: Array = [1, 2, 3, 4]
Output: Sum = 10
Q38. Write a C# program to find the product of two numbers using a function.
Input: Number1 = 5, Number2 = 4
Output: Product = 20
Q39. Write a C# program to calculate the square root of a number using a function.
Input: Number = 16
Output: Square root = 4
Q40. Write a C# program to calculate the sum of all numbers from 1 to n using a function.
Input: n = 5
Output: Sum = 15
Q41. Write a C# program to swap two numbers using a function.
Input: Number1 = 5, Number2 = 10
Output: Number1 = 10, Number2 = 5
Q42. Write a C# program to find the largest of three numbers using a function.
Input: Number1 = 10, Number2 = 20, Number3 = 30
Output: Largest = 30
Q43. Write a C# program to check if a string contains only digits using a function.
Input: String = "12345"
Output: Contains only digits
Q44. Write a C# program to count the number of words in a string using a function.
Input: String = "Hello World"
Output: Word count = 2
Q45. Write a C# program to check whether a string is a number using a function.
Input: String = "123"
Output: Is a number
Q46. Write a C# program to find the sum of prime numbers in an array using a function.
Input: Array = [2, 3, 4, 5, 6]
Output: Sum of primes = 10
Q47. Write a C# program to find the GCD (Greatest Common Divisor) of two numbers using a function.
Input: Number1 = 12, Number2 = 18
Output: GCD = 6
Q48. Write a C# program to find the LCM (Least Common Multiple) of two numbers using a function.
Input: Number1 = 12, Number2 = 18
Output: LCM = 36
Q49. Write a C# program to check if a number is an Armstrong number using a function.
Input: Number = 153
Output: Armstrong number
Q50. Write a C# program to find the number of occurrences of a word in a string using a function.
Input: String = "apple banana apple", Word = "apple"
Output: Occurrences = 2
Q51. Write a C# program to calculate the sum of squares of numbers from 1 to n using a function.
Input: n = 3
Output: Sum of squares = 14
Q52. Write a C# program to reverse an array using a function.
Input: Array = [1, 2, 3, 4]
Output: [4, 3, 2, 1]
Q53. Write a C# program to calculate the Fibonacci sequence up to n terms using a function.
Input: n = 5
Output: Fibonacci sequence = 0 1 1 2 3
Q54. Write a C# program to find the index of a specific element in an array using a function.
Input: Array = [1, 2, 3, 4], Element = 3
Output: Index = 2
Q55. Write a C# program to print a multiplication table of a number using a function.
Input: Number = 5
Output: 5 10 15 20 25 30 35 40 45 50
Q56. Write a C# program to count the number of occurrences of a specific character in a string using a function.
Input: String = "banana", Character = 'a'
Output: Occurrences = 3
Q57. Write a C# program to find the second smallest number in an array using a function.
Input: Array = [10, 20, 5, 30]
Output: Second smallest = 10
Q58. Write a C# program to check if a string is an anagram of another string using a function.
Input: String1 = "listen", String2 = "silent"
Output: Anagram
Q59. Write a C# program to find the sum of even and odd numbers in an array using a function.
Input: Array = [1, 2, 3, 4, 5]
Output: Even sum = 6, Odd sum = 9
Q60. Write a C# program to generate a random number within a range using a function.
Input: Range = 1 to 10
Output: Random number = 7
Q61. Write a C# program to sort an array in ascending order using a function.
Input: Array = [5, 2, 8, 3]
Output: [2, 3, 5, 8]
Q62. Write a C# program to check if a number is an Armstrong number using recursion.
Input: Number = 153
Output: Armstrong number
Q63. Write a C# program to find the largest palindrome number from a list using a function.
Input: Array = [121, 123, 323, 455]
Output: Largest palindrome = 323
Q64. Write a C# program to find the median of an array using a function.
Input: Array = [1, 3, 5, 7, 9]
Output: Median = 5
Q65. Write a C# program to check if a string contains only uppercase letters using a function.
Input: String = "HELLO"
Output: Contains only uppercase
Q66. Write a C# program to check if a string contains only lowercase letters using a function.
Input: String = "hello"
Output: Contains only lowercase
Q67. Write a C# program to replace all occurrences of a substring in a string using a function.
Input: String = "Hello World, Hello", OldSubstring = "Hello", NewSubstring = "Hi"
Output: Hi World, Hi
Q68. Write a C# program to find the common elements in two arrays using a function.
Input: Array1 = [1, 2, 3, 4], Array2 = [3, 4, 5, 6]
Output: [3, 4]
Q69. Write a C# program to find the sum of the squares of even numbers in an array using a function.
Input: Array = [1, 2, 3, 4, 5]
Output: Sum of squares of evens = 20
Q70. Write a C# program to calculate the sum of all positive numbers in an array using a function.
Input: Array = [-1, 2, 3, -4, 5]
Output: Sum of positive numbers = 10