0% found this document useful (0 votes)
2 views

Practice_Lab 1_Revision of C ProgrammingSNU

This document outlines a series of C programming assignments aimed at practicing various programming concepts. Tasks include writing functions for swapping integers, manipulating arrays, implementing linear and binary search, and performing sorting algorithms. The assignments also involve file operations and data management using arrays and structures.

Uploaded by

vignesh.zap.4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Practice_Lab 1_Revision of C ProgrammingSNU

This document outlines a series of C programming assignments aimed at practicing various programming concepts. Tasks include writing functions for swapping integers, manipulating arrays, implementing linear and binary search, and performing sorting algorithms. The assignments also involve file operations and data management using arrays and structures.

Uploaded by

vignesh.zap.4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practice Lab Assignment 1

Practice Lab Assignment 1

The purpose of this assignment is to practice C Programming.

1. Write a program which asks the user to enter two integers a and b. Print the values. The
values are passed on to two functions which return the swapped values of a and b. Print
the values in the main program now. (Hint: Use Call by Value)

2. Write a program which asks the user to enter two integers a and b. Print the values.
Pass the values to a single function which returns the swapped values back to the main
function. Print the values again. (Hint: Use Call by Reference)

3. Prepare a .txt file DAT4 to store the integers 12, 27, 30, 45, 58, 61, 75, 82, 90, 98.
Read the values into an array A and print the values in the stored order and also in reverse
order.

4. Copy DAT4 above into an array B, shift all elements one position to left. Assign value
0 to last position. Count number of shifts as COUNT. Now print array B and check that it
prints 27, 30, 45, 58, 61, 75, 82, 90, 98, 0. Also print value of COUNT.

5. Copy DAT5 into array BETA. Note that it is a sorted array. Write a program to
implement linear search. Search for elements given below and for each case indicate
number of searches in each case
66, 88, 97, 34, 40, 54, 24, 99, 73
Also print the maximum number of searches.

6. Repeat the above problem but this time use binary search.

7. Now let DAT5 represent ID numbers of 36 students. Create a dataset containing ID


numbers and marks obtained by the students in 5 subjects. Let the marks be identical for
all students. Use multiple arrays or arrays of structures to hold the data. Now from this
array, delete the data corresponding to student with ID 14. Shift the remaining data left to
fill up the hole created by deletion. Let the last entry be ID 0 with all marks as zeroes.
Count and print the total number of data movements (shifts) to carry out this operation.

8. Continue with the array structure of the above program after deletion has been done.
Now insert a new student in the database with ID 20 at the appropriate place maintaining
the sorted array structure. Marks for this student will be same as of other students. Count
and print the total number of data movements (shifts) to carry out this operation.

9. Create a data set RAN with 20 random integers. Load the data in an array. Use
Selection Sort to sort the array in descending order and print it out. Count the number of
times array elements are searched and moved. Save the elements in data file SELECT1.

10. Load the data of SELECT1 in an array. Use Selection sort to sort the array in
ascending order and print it out. Count the number of times array elements are moved.
Save the elements in data file SELECT2.

11. Load the dataset RAN into an array. Sort the data in descending order using
INSERTION sort. Count the number of times array elements are moved. Save the
elements in data file SELECT3.

12. Create a dataset ALLRAN with 100 random values between the range 1 to 2000.
Load the data in an array. Use Selection Sort to sort the array in descending order and
print it out. Count the number of times array elements are moved. Save the elements in
data file SELECT4.

13. Load the data of SELECT4 in an array. Check the array for any duplicate elements. If
a number gets repeated, subtract 1 to one of the duplicates maintaining the sorted array
structure. Use Selection sort to sort the array in ascending order and print it out. Count the
number of times array elements are moved. Save the elements in data file SELECT2.

You might also like