Chapter 4 – Assignment
C Programming
Subject: Computer Science
Chapter: 4 – C Programming
Topics: Pointers and Functions, Structure and Array, File Handling
Deadline: Mangshir 14
📌 General Instructions
- Write
all questions and their solutions on white A4-size paper. Use blue or
black ink for the questions and a different colour (either blue or black)
for the answers.
- Take a
screenshot of the output of each program, print it, and paste it below or
beside the corresponding solution on a white A4-size sheet.
- Follow
these instructions for all relevant programming questions.
Section A: Pointers and Functions
1. Define pointer. Write down the advantages and
disadvantages of pointer. Write a program to swap any two numbers using
pointer.
2. Write a C program to check odd/even using pointer.
3. Define function. Write a program to find simple
interest using user-defined function in C.
4. What is recursive function? Write a recursive
program to find the factorial of an input number.
5. What is recursion? Write a recursive function to
find the Fibonacci value of an input number.
6. Write a recursive program to display the sum of
numbers up to the number input by the user.
Section B: Structure and Array
7. WAP to read any ten integer numbers into an array,
sort and display them in descending order.
8. WAP using structure to input employee ID, name,
and salary and print the entered data in sorted form on the basis of salary
(from highest to lowest).
9. WAP to enter name, roll number, and marks of 10
students and sort them in alphabetical order according to their names.
10. WAP to ask employee ID, name, and salary of some
employees and display the records whose salary ranges from 50000 to 100000.
11. Develop a program in C using structure to ask the
information of any 12 students with roll number, name, and marks scored in
three subjects. Also display them in proper format with the calculation of
total and percentage. [Note: Full marks of each subject is 100.]
12. Write a C program that reads the account number,
name, and address of ten customers from users and displays the account number,
name, and address of these customers using array and structure.
13. What are the components of a function of C?
Describe the Call-by-Value and Call-by-Reference and passing the function
parameters.
14. Write a C program that uses structures to
represent details of five books (title, author, publisher, and price) and
prints them out.
15. Differentiate between structure and union in C
with any four points. Write a suitable example of each.
16. What is a union in C? Write a C program to
declare a union named Employee with members ID, name, and salary. Assign and
display the values of its members.
Section C: File Handling
17. Write a program to create a data file named
"student.dat" and store roll number, name, and address of 10 students
and display the records in proper format.
18. Let a database book.txt contain information of
books (name, price, and edition). WAP in C language to add some more data as
per user's choice.
19. WAP to read the marks of 5 students in English,
Account, and Computer and count how many students passed or failed in the exam.
20. Write a C program to input the name and marks in
three subjects: English, Computer, and Nepali, and display the records of only
those students who have passed all three subjects. Assume the full marks of
English and Nepali are 75 each and Computer is 50. The pass mark is 35% of the
full marks in each subject. [5]
21. A file named employee.txt contains the employee
ID, name, post, and salary of several employees. Write a C program to read the
records from the file and display the details of employees whose salary is
greater than Rs. 90,000.
22. Discuss the concept of binary file handling in C
programming and explain how putw() and getw() functions facilitate binary
input/output operations. Give examples.
23. A file named result.txt contains the name and
marks of several students. Write a C program to read the records from the file
and display the names of students who have obtained more than 80 marks.
24. Write a C program to read the contents of a file named source.txt and copy them into another file named destination.txt. Display an appropriate message after copying the contents successfully
