Practice_Lab 1_Revision of C ProgrammingSNU
Practice_Lab 1_Revision of C ProgrammingSNU
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.
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.