DEV Community

Codes With Pankaj
Codes With Pankaj

Posted on

100 Interview Questions C

100 Interview Questions -

View on GitHub

  1. Question 1: Question: Write a C program that prints numbers from 1 to 10 using a for loop. Expected Output:
   1 2 3 4 5 6 7 8 9 10
Enter fullscreen mode Exit fullscreen mode
  1. Question 2: Question: Create a C program that prints the even numbers from 2 to 20 using a while loop. Expected Output:
   2 4 6 8 10 12 14 16 18 20
Enter fullscreen mode Exit fullscreen mode
  1. Question 3: Question: Develop a program that calculates the sum of numbers from 1 to 100 using a for loop. Expected Output:
   The sum of numbers from 1 to 100 is 5050.
Enter fullscreen mode Exit fullscreen mode
  1. Question 4: Question: Write a C program that prints the first 10 terms of the Fibonacci sequence using a do-while loop. Expected Output:
   Fibonacci series: 0 1 1 2 3 5 8 13 21 34
Enter fullscreen mode Exit fullscreen mode
  1. Question 5: Question: Create a program that prompts the user to enter a positive integer and then prints the multiplication table for that number from 1 to 10 using a for loop. Expected Output:
   Enter a number: 7
   Multiplication table for 7:
   7 x 1 = 7
   7 x 2 = 14
   ...
   7 x 10 = 70
Enter fullscreen mode Exit fullscreen mode
  1. Question 6: Question: Develop a C program that prints a pattern of asterisks in the shape of a right-angled triangle using nested for loops. Expected Output:
   *
   **
   ***
   ****
   *****
Enter fullscreen mode Exit fullscreen mode
  1. Question 7: Question: Write a program that calculates the factorial of a user-entered number using a while loop. Expected Output:
   Enter a number: 5
   The factorial of 5 is 120.
Enter fullscreen mode Exit fullscreen mode
  1. Question 8: Question: Create a C program that checks if a user-entered number is a prime number using a for loop. Expected Output:
   Enter a number: 17
   17 is a prime number.
Enter fullscreen mode Exit fullscreen mode
  1. Question 9: Question: Develop a program that finds and displays the prime numbers in a given range (e.g., 1 to 100) using a for loop. Expected Output:
   Prime numbers in the range 1 to 100 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Enter fullscreen mode Exit fullscreen mode
  1. Question 10:
    Question: Write a C program that prints the ASCII values and characters for all printable characters (from ' ' to '~') using a for loop.
    Expected Output:

    ASCII values and characters for printable characters:
    ' ' (Space) - ASCII: 32
    '!' - ASCII: 33
    '"' - ASCII: 34
    ...
    '~' - ASCII: 126
    
  2. Question 11:
    Question: Create a C program that calculates the sum of all even numbers between 1 and 50 using a for loop.
    Expected Output:

    The sum of even numbers from 1 to 50 is 650.
    
  3. Question 12:
    Question: Write a C program that checks if a user-entered number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself).
    Expected Output:

    Enter a number: 28
    28 is a perfect number.
    
  4. Question 13:
    Question: Develop a program that calculates the factorial of a user-entered number using a do-while loop.
    Expected Output:

    Enter a number: 6
    The factorial of 6 is 720.
    
  5. Question 14:
    Question: Create a C program that prints the squares of numbers from 1 to 10 using a for loop.
    Expected Output:

    1^2 = 1
    2^2 = 4
    3^2 = 9
    ...
    10^2 = 100
    
  6. Question 15:
    Question: Write a C program that calculates the sum of a geometric series (1 + 2 + 4 + 8 + ... + 2^n) using a for loop. Prompt the user for the number of terms (n).
    Expected Output:

    Enter the number of terms (n): 5
    The sum of the geometric series is 31.
    
  7. Question 16:
    Question: Develop a C program that prints the first n terms of the square root series (1, sqrt(2), sqrt(3), ...) using a for loop.
    Expected Output:

    Enter the number of terms (n): 4
    Square root series: 1.000 1.414 1.732 2.000
    
  8. Question 17:
    Question: Create a program that calculates the sum of an arithmetic series (3 + 7 + 11 + ... + 3n - 1) using a for loop. Prompt the user for the number of terms (n).
    Expected Output:

    Enter the number of terms (n): 5
    The sum of the arithmetic series is 75.
    
  9. Question 18:
    Question: Write a C program that prints the numbers from 100 to 1 in reverse order using a while loop.
    Expected Output:

    100 99 98 97 96 ... 4 3 2 1
    
  10. Question 19:
    Question: Develop a program that generates and displays the Collatz sequence starting from a user-entered number. The Collatz sequence for a positive integer n is defined as follows: if n is even, divide it by 2; if n is odd, multiply it by 3 and add 1.
    Expected Output:

    Enter a number: 10
    Collatz sequence: 10 5 16 8 4 2 1
    
  11. Question 20:
    Question: Create a C program that calculates and displays the GCD (greatest common divisor) of two user-entered numbers using the Euclidean algorithm in a while loop.
    Expected Output:

    Enter the first number: 24
    Enter the second number: 18
    The GCD of 24 and 18 is 6.
    
  12. Question 21:
    Question: Write a C program to check if a user-entered number is a palindrome. A palindrome is a number that reads the same forwards and backwards.
    Expected Output:

    Enter a number: 121
    121 is a palindrome.
    
  13. Question 22:
    Question: Create a C program that prints a pattern of stars in the shape of a diamond using nested for loops.
    Expected Output:

       *
      ***
     *****
    *******
     *****
      ***
       *
    
  14. Question 23:
    Question: Develop a program that generates and displays a random number between 1 and 100. Prompt the user to guess the number, and provide hints.
    Expected Output:

    Guess the number (1-100): 50
    Try higher.
    Guess the number (1-100): 75
    Try lower.
    Guess the number (1-100): 63
    Congratulations! You guessed the number (63).
    
  15. Question 24:
    Question: Write a C program that calculates the sum of the series 1 - 1/2 + 1/3 - 1/4 + ... - 1/n for a user-entered positive integer n.
    Expected Output:

    Enter a positive integer (n): 5
    The sum of the series is -0.78333.
    
  16. Question 25:
    Question: Create a C program that simulates a simple game of rock-paper-scissors. The user plays against the computer.
    Expected Output:

    Choose your move (rock, paper, scissors): rock
    Computer's move: scissors
    You win!
    
  17. Question 26:
    Question: Develop a program that calculates the value of π using the Leibniz formula. Prompt the user for the number of terms (n) to use in the formula.
    Expected Output:

    Enter the number of terms (n): 1000000
    The value of π is approximately 3.14159.
    
  18. Question 27:
    Question: Write a C program that generates a random password of a specified length (e.g., 8 characters) containing a mix of letters (both uppercase and lowercase) and numbers.
    Expected Output:

    Your random password: K4rW8p7X
    
  19. Question 28:
    Question: Create a C program that simulates a simple guessing game. The program generates a random number between 1 and 100, and the user must guess it within a limited number of attempts.
    Expected Output:

    Guess the number (1-100). You have 5 attempts.
    Attempt 1: 50
    Try higher.
    Attempt 2: 75
    Try lower.
    ...
    Congratulations! You guessed the number (63) in 4 attempts.
    
  20. Question 29:
    Question: Develop a program that calculates the sum of all prime numbers between 1 and 100 using a for loop.
    Expected Output:

    The sum of prime numbers between 1 and 100 is 1060.
    
  21. Question 30:
    Question: Write a C program that generates and displays a magic square of order 3. A magic square is a square matrix in which the sum of the numbers in each row, column, and both main diagonals is the same.
    Expected Output:

    Magic Square:
    2 7 6
    9 5 1
    4 3 8
    
  22. Question 31:
    Question: Create a C program that prints a right-angled triangle pattern of asterisks using nested for loops.
    Expected Output:

    *
    **
    ***
    ****
    *****
    
  23. Question 32:
    Question: Develop a program that prints a hollow square pattern of asterisks with a user-specified side length.
    Expected Output:

    Enter the side length of the square: 5
    *****
    *   *
    *   *
    *   *
    *****
    
  24. Question 33:
    Question: Write a C program that prints a mirrored right-angled triangle pattern of numbers.
    Expected Output:

        1
       12
      123
     1234
    12345
    
  25. Question 34:
    Question: Create a program that prints a pyramid pattern of asterisks with a user-specified height.
    Expected Output:

        *
       ***
      *****
     *******
    *********
    
  26. Question 35:
    Question: Develop a C program that prints a diamond pattern of numbers with a user-specified number of rows.
    Expected Output:

        1
       121
      12321
     1234321
    123454321
     1234321
      12321
       121
        1
    
  27. Question 36:
    Question: Write a C program that prints a right-angled triangle pattern of uppercase letters starting from 'A'.
    Expected Output:

    A
    AB
    ABC
    ABCD
    ABCDE
    
  28. Question 37:
    Question: Create a program that prints a hollow right-angled triangle pattern of asterisks with a user-specified height.
    Expected Output:

    Enter the height of the triangle: 5
    *
    **
    * *
    *  *
    *****
    
  29. Question 38:
    Question: Develop a C program that prints an inverted pyramid pattern of numbers.
    Expected Output:

    12345
     1234
      123
       12
        1
    
  30. Question 39:
    Question: Write a program that prints a square pattern of numbers with each row starting from 1 and incrementing by 1.
    Expected Output:

    12345
    12345
    12345
    12345
    12345
    
  31. Question 40:
    Question: Create a C program that prints a pattern of the letter 'X' formed by asterisks.
    Expected Output:

    *       *
     *     *
      *   *
       * *
        *
       * *
      *   *
     *     *
    *       *
    
  32. Question 41:
    Question: Write a C program to calculate the sum of the first 10 natural numbers using a while loop.
    Expected Output:

    The sum of the first 10 natural numbers is 55.
    
  33. Question 42:
    Question: Create a C program that prints a hollow square pattern of asterisks with a user-specified side length.
    Expected Output:

    Enter the side length of the square: 5
    *****
    *   *
    *   *
    *   *
    *****
    
  34. Question 43:
    Question: Write a C program that checks if a given number is a power of two (2^n).
    Expected Output:

    Enter a number: 16
    16 is a power of 2.
    
  35. Question 44:
    Question: Create a C program to find the factorial of a user-entered number using a while loop.
    Expected Output:

    Enter a number: 5
    The factorial of 5 is 120.
    
  36. Question 45:
    Question: Develop a program that calculates the sum of all odd numbers from 1 to 100 using a for loop.
    Expected Output:

    The sum of odd numbers from 1 to 100 is 2500.
    
  37. Question 46:
    Question: Write a C program that calculates the sum of the digits of a user-entered integer.
    Expected Output:

    Enter an integer: 12345
    The sum of the digits is 15.
    
  38. Question 47:
    Question: Create a program that calculates the LCM (Least Common Multiple) of two user-entered numbers.
    Expected Output:

    Enter two numbers (separated by a space): 12 18
    The LCM of 12 and 18 is 36.
    
  39. Question 48:
    Question: Develop a C program that checks if a user-entered string is a palindrome (reads the same forwards and backwards).
    Expected Output:

    Enter a string: radar
    "radar" is a palindrome.
    
  40. Question 49:
    Question: Write a C program that calculates the sum of all the multiples of 3 and 5 between 1 and 100.
    Expected Output:

    The sum of multiples of 3 and 5 between 1 and 100 is 2418.
    
  41. Question 50:
    Question: Create a program that finds and displays the first N prime numbers.
    Expected Output:

    Enter the value of N: 10
    The first 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29
    
  42. Question 51:
    Question: Develop a program that checks if a user-entered year is a leap year using a logical operator.
    Expected Output:

    Enter a year: 2024
    2024 is a leap year.
    
  43. Question 52:
    Question: Write a C program that calculates and displays the GCD (greatest common divisor) of two user-entered numbers.
    Expected Output:

    Enter two numbers (separated by a space): 24 18
    The GCD of 24 and 18 is 6.
    
  44. Question 53:
    Question: Create a program that calculates the sum of squares of the first N natural numbers.
    Expected Output:

    Enter the value of N: 4
    The sum of squares of the first 4 natural numbers is 30.
    
  45. Question 54:
    Question: Develop a program that finds the smallest and largest elements in an array of integers.
    Expected Output:

    Enter the number of elements in the array: 6
    Enter the elements (separated by spaces): 18 7 42 10 31 55
    The smallest element in the array is 7, and the largest element is 55.
    
  46. Question 55:
    Question: Write a C program that generates and displays a random password of a specified length (e.g., 8 characters) using a logical approach.
    Expected Output:

    Your random password: K4rW8p7X
    
  47. Question 56:
    Question: Create a program that checks if a user-entered number is a perfect number.
    Expected Output:

    Enter a number: 28
    28 is a perfect number.
    
  48. Question 57:
    Question: Develop a C program that prints a pattern of stars in the shape of a right-angled triangle using nested for loops.
    Expected Output:

    *
    **
    ***
    ****
    *****
    
  49. Question 58:
    Question: Write a program that calculates the sum of even numbers between 1 and 50 using a while loop.
    Expected Output:

    The sum of even numbers from 1 to 50 is 650.
    
  50. Question 59:
    Question: Create a C program that checks if a given number is a palindrome using a logical approach.
    Expected Output:

    Enter a number: 121
    121 is a palindrome.
    
  51. Question 60:
    Question: Write a C program that checks if a user-entered string is a palindrome using logical operations.
    Expected Output:

    Enter a string: radar
    "radar" is a palindrome.
    
  52. Question 61:
    Question: Develop a C program that finds and displays the first N Fibonacci numbers.
    Expected Output:

    Enter the value of N: 8
    The first 8 Fibonacci numbers are: 0 1 1 2 3 5 8 13
    
  53. Question 62:
    Question: Write a C program to reverse a user-entered string without using any built-in string functions.
    Expected Output:

    Enter a string: programming
    Reversed string: gnimmargorp
    
  54. Question 63:
    Question: Create a program that checks if a given year is a leap year or not using a logical approach.
    Expected Output:

    Enter a year: 2100
    2100 is not a leap year.
    
  55. Question 64:
    Question: Develop a C program that calculates the product of digits in a user-entered integer.
    Expected Output:

    Enter an integer: 12345
    The product of the digits is 120.
    
  56. Question 65:
    Question: Write a program that determines if a user-entered number is prime or composite.
    Expected Output:

    Enter a number: 17
    17 is a prime number.
    
  57. Question 66:
    Question: Create a C program that counts and displays the number of words in a user-entered sentence.
    Expected Output:

    Enter a sentence: This is a sample sentence.
    The number of words in the sentence is 5.
    
  58. Question 67:
    Question: Develop a program that calculates the sum of all natural numbers divisible by 3 or 5 between 1 and 100.
    Expected Output:

    The sum of natural numbers divisible by 3 or 5 between 1 and 100 is 2418.
    
  59. Question 68:
    Question: Write a C program to check if a user-entered number is an Armstrong number (narcissistic number).
    Expected Output:

    Enter a number: 153
    153 is an Armstrong number.
    
  60. Question 69:
    Question: Create a program that calculates the area of a triangle when the user provides the lengths of its three sides.
    Expected Output:

    Enter the lengths of three sides (separated by spaces): 5 12 13
    The area of the triangle is 30 square units.
    
  61. Question 70:
    Question: Develop a C program to check if a user-entered number is a strong number.
    Expected Output:

    Enter a number: 145
    145 is a strong number.
    
  62. Question 71:
    Question: Write a C program that checks if a user-entered number is a palindrome using a logical approach.
    Expected Output:

    Enter a number: 121
    121 is a palindrome.
    
  63. Question 72:
    Question: Create a program that calculates the sum of squares of the first N even natural numbers.
    Expected Output:

    Enter the value of N: 4
    The sum of squares of the first 4 even natural numbers is 120.
    
  64. Question 73:
    Question: Develop a C program that checks if a user-entered year is a leap year without using logical operators.
    Expected Output:

    Enter a year: 2024
    2024 is a leap year.
    
  65. Question 74:
    Question: Write a program that calculates the sum of cubes of the first N odd natural numbers.
    Expected Output:

    Enter the value of N: 5
    The sum of cubes of the first 5 odd natural numbers is 135.
    
  66. Question 75:
    Question: Create a C program that checks if a user-entered string is a pangram (contains all English alphabet letters).
    Expected Output:

    Enter a string: The quick brown fox jumps over the lazy dog.
    The string is a pangram.
    
  67. Question 76:
    Question: Develop a program that calculates and displays the HCF (Highest Common Factor) of two user-entered numbers.
    Expected Output:

    Enter two numbers (separated by a space): 24 36
    The HCF of 24 and 36 is 12.
    
  68. Question 77:
    Question: Write a C program that calculates the sum of the squares of prime numbers between 1 and 50.
    Expected Output:

    The sum of squares of prime numbers between 1 and 50 is 2418.
    
  69. Question 78:
    Question: Create a program that checks if a user-entered number is an abundant number.
    Expected Output:

    Enter a number: 12
    12 is an abundant number.
    
  70. Question 79:
    Question: Develop a C program that checks if a given string is a palindrome using pointers.
    Expected Output:

    Enter a string: racecar
    "racecar" is a palindrome.
    
  71. Question 80:
    Question: Write a program that calculates the sum of digits of a user-entered number using a logical approach.
    Expected Output:

    Enter a number: 12345
    The sum of the digits is 15.
    
  72. Question 81:
    Question: Create a C program to find and display the prime factors of a user-entered number.
    Expected Output:

    Enter a number: 60
    The prime factors of 60 are: 2 3 5
    
  73. Question 82:
    Question: Develop a program that calculates the difference between the sum of squares and the square of the sum of the first N natural numbers.
    Expected Output:

    Enter the value of N: 5
    The difference is 170.
    
  74. Question 83:
    Question: Write a C program that checks if a user-entered number is a strong number using logical operations.
    Expected Output:

    Enter a number: 145
    145 is a strong number.
    
  75. Question 84:
    Question: Create a program that calculates and displays the LCM (Least Common Multiple) of three user-entered numbers.
    Expected Output:

    Enter three numbers (separated by spaces): 12 18 24
    The LCM of 12, 18, and 24 is 72.
    
  76. Question 85:
    Question: Develop a C program that calculates the sum of natural numbers divisible by both 3 and 5 between 1 and 100.
    Expected Output:

    The sum of natural numbers divisible by both 3 and 5 between 1 and 100 is 315.
    
  77. Question 86:
    Question: Write a program that checks if a user-entered number is a Kaprekar number.
    Expected Output:

    Enter a number: 9
    9 is a Kaprekar number.
    
  78. Question 87:
    Question: Create a C program to find the sum of the series: 1 + 1/4 + 1/9 + 1/16 + ... + 1/n^2.
    Expected Output:

    Enter the value of n: 4
    The sum of the series is approximately 1.42361.
    
  79. Question 88:
    Question: Develop a program that checks if a user-entered sentence is a palindrome (ignoring spaces and case).
    Expected Output:

    Enter a sentence: A man, a plan, a canal, Panama.
    The sentence is a palindrome.
    
  80. Question 89:
    Question: Write a C program that calculates and displays the difference between the sum of even-indexed elements and odd-indexed elements in an array.
    Expected Output:

    Enter the number of elements in the array: 5
    Enter the elements (separated by spaces): 4 7 2 9 6
    The difference is 7.
    
  81. Question 90:
    Question: Create a program that calculates the value of π using the Monte Carlo method for a user-specified number of iterations.
    Expected Output:

    Enter the number of iterations: 1000000
    The value of π is approximately 3.14159.
    
  82. Question 91:
    Question: Write a C program that generates the first N prime numbers and displays them in a spiral pattern.
    Expected Output:

    Enter the value of N: 10
    Prime Numbers in a Spiral:
    17 16 15 14 13
    18  5  4  3 12
    19  6  1  2 11
    20  7  8  9 10
    21 22 23 24 25
    
  83. Question 92:
    Question: Create a program that simulates a basic ATM machine. The user can withdraw, deposit, or check the balance.
    Expected Output: (Interaction example)

    Welcome to the ATM!
    Select an option:
    1. Withdraw
    2. Deposit
    3. Check Balance
    4. Exit
    Enter your choice: 1
    Enter the amount to withdraw: 100
    Successfully withdrawn $100. Current balance: $900
    
  84. Question 93:
    Question: Develop a C program that simulates a simple tic-tac-toe game for two players.
    Expected Output: (Sample game interaction)

    Player 1, enter your move (row and column): 2 1
    Board after move:
    1 - -
    X - -
    - - -
    Player 2, enter your move (row and column): 1 2
    Board after move:
    1 O -
    X - -
    - - -
    ...
    
  85. Question 94:
    Question: Write a C program to find and display the longest word in a user-entered sentence.
    Expected Output:

    Enter a sentence: The quick brown fox jumps over the lazy dog.
    The longest word in the sentence is "jumps".
    
  86. Question 95:
    Question: Create a program that generates a random maze and finds a path from the start to the end point.
    Expected Output:

    Random Maze:
    # # # # # # # # # # #
    S       #   #       #
    # # #   # # #   # # #
    #   #   #       #   #
    #   # # #   # # # # #
    #   #           #   E
    # # # # # # # # # # #
    Path:
    S   * * * * * *   *
        *       #   * #
    # # #   # # #   # #
    #   #   #       # #
    #   # # #   # # # #
    #   #           # *
    # # # # # # # # # #
    
  87. Question 96:
    Question: Develop a C program that simulates a simple Blackjack card game between the user and the computer.
    Expected Output: (Sample game interaction)

    Welcome to Blackjack!
    Player's Hand: 7 9
    Computer's Hand: 5 ?
    Do you want to hit or stand? (h/s): h
    Player's Hand: 7 9 Q
    ...
    
  88. Question 97:
    Question: Write a program to calculate the sum of prime numbers in the Fibonacci sequence up to a user-entered limit.
    Expected Output:

    Enter the limit: 50
    The sum of prime Fibonacci numbers up to 50 is 104.
    
  89. Question 98:
    Question: Create a C program that counts the number of occurrences of each word in a user-entered text document.
    Expected Output: (Sample input and output)

    Enter the text:
    This is a sample text. This is a sample document.
    Word Count:
    "This" occurs 2 times.
    "is" occurs 2 times.
    "a" occurs 2 times.
    "sample" occurs 2 times.
    "text." occurs 1 time.
    "document." occurs 1 time.
    
  90. Question 99:
    Question: Develop a program that calculates and displays the sum of digits of factorial of a user-entered number.
    Expected Output:

    Enter a number: 5
    The sum of digits of 5! is 3.
    
  91. Question 100:
    Question: Write a C program that generates and displays the first N numbers of the Lucas sequence.
    Expected Output:

    Enter the value of N: 8
    The first 8 Lucas numbers are: 2 1 3 4 7 11 18 29
    

Top comments (0)