Practice Questions: C Arrays and Basics of C Programming
Mandatory Homework
The following practice questions are designed to revise and strengthen the basics of C
programming, particularly arrays, loops, conditional statements, patterns, and searching.
Instructions:
• This homework is mandatory for all students.
• Every student must write the complete C code by hand and bring the handwritten code
to class.
• Students must also implement, compile, and execute each program at home before
coming to class.
• Do not simply copy the code. Try to understand the logic, syntax, loops, conditions, and
array operations used in each program.
• The purpose of this practice is to brush up on the fundamentals of C programming
before moving on to more advanced concepts.
1. Write a C program to print the following pattern for n rows, where the value of n is entered
by the user.
Example: For n = 5:
1
12
123
1234
12345
2. Write a C program that takes three integers as input from the user and finds the largest
among them using conditional statements (if-else).
3. Write a C program to find all duplicate elements in an array. The program should take
the size of the array (n) as input from the user, followed by the n array elements.
Identify and display all elements that occur more than once in the array.
Example:
Input: n = 8 Output: 2 5 3
Array: 2 5 3 2 8 5 1 3
4. Write a C program to input the size of an array and its elements from the user. Then,
input an element to be searched. Using linear search, determine whether the element is
present in the array. If found, display its position; otherwise, display "Element not found".
Example:
Input: Size of array: 6 Output: Element found at position 4
Array elements: 12 25 7 18 30 9
Element to search: 18