Tutorial Questions for Arrays, Functions and Files
Tutorial Questions for Arrays, Functions and Files
1. Write a C function isprime(num) that accepts an integer argument and returns 1 if the
argument is prime, a 0 otherwise. Write a C program that invokes this function to
generate prime numbers between the given ranges.
2. Write a program that arranges the positive and negative numbers in a one-dimensional array so
that all positive numbers come first and then all the negative numbers come without changing
the original sequence of the numbers.
3. Write a function check (x, y, n) that returns 1 if both x and y fall between 0 and n-1,
inclusive. The function should return 0 otherwise. Assume that x, y, and n are all of
type integers. Then, write a main program to test the function.
4. Write a program that accepts n integers into a one-dimensional array, calculates the
sum and average of the array elements, and displays the results.
5. Write a program to reverse the elements of a one-dimensional array without using
another array.
6. Write a program to find all duplicate elements in a one-dimensional array and print
them.
7. Write a program to add two 2x2 matrices and display the resultant matrix.
8. Write a program to subtract one 2x2 matrix from another and display the resultant
matrix.
9. Write two functions: one for converting Fahrenheit to Celsius and another for
converting Celsius to Fahrenheit. Test both functions in a program.
10. Write a function isLeapYear(int year) that checks whether a given year is a leap year.
Use it in a program to display all leap years in a given range.
11. Write a program to store student records (name, ID, and marks) in a file. Then, read the
data and display it in a formatted way.
12. Write a program to read the content of a text file and write it to another file.