Practice 100 C# Basic Programming Questions
Q1. Write a C# program to add two numbers.
Input: 5, 10
Output: 15
Q2. Write a C# program to subtract two numbers.
Input: 20, 8
Output: 12
Q3. Write a C# program to multiply two numbers.
Input: 4, 6
Output: 24
Q4. Write a C# program to divide two numbers.
Input: 25, 5
Output: 5
Q5. Write a C# program to find the remainder of two numbers.
Input: 15, 4
Output: 3
Q6. Write a C# program to swap two numbers using a temporary variable.
Input: x = 10, y = 20
Output: x = 20, y = 10
Q7. Write a C# program to swap two numbers without using a temporary variable.
Input: a = 15, b = 25
Output: a = 25, b = 15
Q8. Write a C# program to check if a number is even or odd.
Input: 7
Output: Odd
Q9. Write a C# program to check if a number is positive, negative, or zero.
Input: -5
Output: Negative
Q10. Write a C# program to find the largest of three numbers.
Input: 3, 7, 5
Output: 7
Q11. Write a C# program to calculate the factorial of a number.
Input: 5
Output: 120
Q12. Write a C# program to calculate the sum of natural numbers up to a given number.
Input: n = 5
Output: 15
Q13. Write a C# program to reverse a number.
Input: 12345
Output: 54321
Q14. Write a C# program to check if a number is a palindrome.
Input: 121
Output: Palindrome
Q15. Write a C# program to check if a number is prime.
Input: 13
Output: Prime
Q16. Write a C# program to find the greatest common divisor (GCD) of two numbers.
Input: 24, 36
Output: 12
Q17. Write a C# program to find the least common multiple (LCM) of two numbers.
Input: 12, 15
Output: 60
Q18. Write a C# program to print the Fibonacci series up to n terms.
Input: n = 5
Output: 0, 1, 1, 2, 3
Q19. Write a C# program to count the number of digits in a number.
Input: 4567
Output: 4
Q20. Write a C# program to calculate the power of a number.
Input: base = 2, exponent = 3
Output: 8
Q21. Write a C# program to check if a character is a vowel or consonant.
Input: a
Output: Vowel
Q22. Write a C# program to check if a year is a leap year.
Input: 2024
Output: Leap Year
Q23. Write a C# program to find the sum of the digits of a number.
Input: 123
Output: 6
Q24. Write a C# program to print all even numbers from 1 to n.
Input: n = 10
Output: 2, 4, 6, 8, 10
Q25. Write a C# program to print all odd numbers from 1 to n.
Input: n = 9
Output: 1, 3, 5, 7, 9
Q26. Write a C# program to check if a number is divisible by both 3 and 5.
Input: 15
Output: Divisible
Q27. Write a C# program to find the ASCII value of a character.
Input: A
Output: 65
Q28. Write a C# program to calculate the simple interest.
Input: P = 1000, R = 5, T = 2
Output: 100
Q29. Write a C# program to find the area of a rectangle.
Input: Length = 5, Width = 10
Output: 50
Q30. Write a C# program to find the perimeter of a rectangle.
Input: Length = 5, Width = 10
Output: 30
Q31. Write a C# program to find the area of a circle.
Input: Radius = 7
Output: 153.94
Q32. Write a C# program to find the circumference of a circle.
Input: Radius = 7
Output: 43.96
Q33. Write a C# program to print the multiplication table of a number.
Input: n = 5
Output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
Q34. Write a C# program to find the square of a number.
Input: 6
Output: 36
Q35. Write a C# program to find the cube of a number.
Input: 3
Output: 27
Q36. Write a C# program to calculate the sum of elements in an array.
Input: [1, 2, 3, 4, 5]
Output: 15
Q37. Write a C# program to find the maximum number in an array.
Input: [10, 20, 5, 7]
Output: 20
Q38. Write a C# program to find the minimum number in an array.
Input: [10, 20, 5, 7]
Output: 5
Q39. Write a C# program to sort an array in ascending order.
Input: [3, 1, 4, 2]
Output: [1, 2, 3, 4]
Q40. Write a C# program to sort an array in descending order.
Input: [3, 1, 4, 2]
Output: [4, 3, 2, 1]
Q41. Write a C# program to search for an element in an array.
Input: Array = [10, 20, 30], Search = 20
Output: Found
Q42. Write a C# program to count the occurrences of an element in an array.
Input: Array = [1, 2, 2, 3, 2], Element = 2
Output: 3
Q43. Write a C# program to check if a string is a palindrome.
Input: madam
Output: Palindrome
Q44. Write a C# program to reverse a string.
Input: hello
Output: olleh
Q45. Write a C# program to count the number of vowels in a string.
Input: programming
Output: 3
Q46. Write a C# program to check if a string contains a substring.
Input: String = "Hello World", Substring = "World"
Output: Found
Q47. Write a C# program to find the length of a string.
Input: C# Programming
Output: 15
Q48. Write a C# program to concatenate two strings.
Input: Hello, World!
Output: HelloWorld!
Q49. Write a C# program to replace all occurrences of a character in a string.
Input: Input = "banana", Replace = 'a', With = 'o'
Output: bonono
Q50. Write a C# program to calculate the average of elements in an array.
Input: [1, 2, 3, 4, 5]
Output: 3
Q51. Write a C# program to remove duplicates from an array.
Input: [1, 2, 2, 3, 4, 4, 5]
Output: [1, 2, 3, 4, 5]
Q52. Write a C# program to find the second largest number in an array.
Input: [10, 20, 5, 7]
Output: 10
Q53. Write a C# program to print all prime numbers between 1 and n.
Input: n = 10
Output: 2, 3, 5, 7
Q54. Write a C# program to find the sum of squares of elements in an array.
Input: [1, 2, 3]
Output: 14
Q55. Write a C# program to find the frequency of characters in a string.
Input: hello
Output: h: 1, e: 1, l: 2, o: 1
Q56. Write a C# program to find the smallest positive number missing from an array.
Input: [1, 2, 3, 5]
Output: 4
Q57. Write a C# program to find the sum of two matrices.
Input:
Matrix1: [[1, 2], [3, 4]]
Matrix2: [[5, 6], [7, 8]]
Output:
[[6, 8], [10, 12]]
Q58. Write a C# program to transpose a matrix.
Input:
[[1, 2], [3, 4]]
Output:
[[1, 3], [2, 4]]
Q59. Write a C# program to check if a string is an anagram of another.
Input: str1 = "listen", str2 = "silent"
Output: Anagram
Q60. Write a C# program to find the HCF (GCD) of an array of numbers.
Input: [12, 15, 21]
Output: 3
Q61. Write a C# program to check if an array is sorted.
Input: [1, 2, 3, 4]
Output: Sorted
Q62. Write a C# program to reverse an array.
Input: [1, 2, 3, 4]
Output: [4, 3, 2, 1]
Q63. Write a C# program to merge two arrays.
Input: [1, 2], [3, 4]
Output: [1, 2, 3, 4]
Q64. Write a C# program to remove all vowels from a string.
Input: hello
Output: hll
Q65. Write a C# program to count the number of words in a string.
Input: C# is fun
Output: 3
Q66. Write a C# program to reverse each word in a sentence.
Input: C# is fun
Output: #C si nuf
Q67. Write a C# program to find the factorial of each element in an array.
Input: [2, 3, 4]
Output: [2, 6, 24]
Q68. Write a C# program to find the intersection of two arrays.
Input: [1, 2, 3], [2, 3, 4]
Output: [2, 3]
Q69. Write a C# program to find the union of two arrays.
Input: [1, 2, 3], [2, 3, 4]
Output: [1, 2, 3, 4]
Q70. Write a C# program to find all permutations of a string.
Input: abc
Output:
abc, acb, bac, bca, cab, cba
Q71. Write a C# program to count the number of 1s in the binary representation of a number.
Input: 5
Output: 2
Q72. Write a C# program to check if a string contains only digits.
Input: 12345
Output: True
Q73. Write a C# program to generate a random number within a given range.
Input: Min = 1, Max = 10
Output: Random Number (e.g., 7)
Q74. Write a C# program to find the average of digits in a number.
Input: 123
Output: 2
Q75. Write a C# program to calculate the product of elements in an array.
Input: [2, 3, 4]
Output: 24
Q76. Write a C# program to check if two strings are rotations of each other.
Input: str1 = "abcd", str2 = "cdab"
Output: True
Q77. Write a C# program to count the frequency of words in a string.
Input: hello world hello
Output: hello: 2, world: 1
Q78. Write a C# program to check if a number is an Armstrong number.
Input: 153
Output: Armstrong
Q79. Write a C# program to find the longest word in a string.
Input: C# is fantastic
Output: fantastic
Q80. Write a C# program to print the Pascal's triangle for n rows.
Input: n = 5
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Q81. Write a C# program to print a right-angled triangle pattern of *.
Input: n = 4
Output:
*
**
***
****
Q82. Write a C# program to print an inverted right-angled triangle pattern of *.
Input: n = 4
Output:
****
***
**
*
Q83. Write a C# program to print a pyramid pattern of *.
Input: n = 4
Output:
*
***
*****
*******
Q84. Write a C# program to print a diamond pattern of *.
Input: n = 4
Output:
*
***
*****
*******
*****
***
*
Q85. Write a C# program to print a hollow square pattern of *.
Input: n = 4
Output:
****
* *
* *
****
Q86. Write a C# program to print a Floyd's triangle pattern.
Input: n = 4
Output:
1
2 3
4 5 6
7 8 9 10
Q87. Write a C# program to print a checkerboard pattern of size n x n.
Input: n = 4
Output:
* * * *
* * * *
* * * *
* * * *
Q88. Write a C# program to calculate the sum of diagonal elements in a matrix.
Input:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output: 15
Q89. Write a C# program to rotate an array to the left by one position.
Input: [1, 2, 3, 4, 5]
Output: [2, 3, 4, 5, 1]
Q90. Write a C# program to rotate an array to the right by one position.
Input: [1, 2, 3, 4, 5]
Output: [5, 1, 2, 3, 4]
Q91. Write a C# program to calculate the sum of the border elements of a matrix.
Input:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output: 28
Q92. Write a C# program to print a hollow pyramid pattern.
Input: n = 4
Output:
*
* *
* *
*******
Q93. Write a C# program to count the frequency of each digit in a number.
Input: 122333
Output:
1: 1
2: 2
3: 3
Q94. Write a C# program to check if all characters in a string are unique.
Input: hello
Output: False
Q95. Write a C# program to print a spiral matrix of size n x n.
Input: n = 3
Output:
1 2 3
8 9 4
7 6 5
Q96. Write a C# program to find the transpose of a given string matrix.
Input:
["abc",
"def",
"ghi"]
Output:
["adg",
"beh",
"cfi"]
Q97. Write a C# program to check if a number is a perfect number.
Input: 28
Output: Perfect Number
Q98. Write a C# program to calculate the digital root of a number.
Input: 9876
Output: 3
Q99. Write a C# program to find the longest increasing subsequence in an array.
Input: [10, 22, 9, 33, 21, 50, 41, 60]
Output: [10, 22, 33, 50, 60]
Q100. Write a C# program to print Pascal's triangle row-wise for a specific row index.
Input: Index = 4
Output: [1, 4, 6, 4, 1]
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!