0% found this document useful (0 votes)
15 views13 pages

MinorAssignment 03 2

The document outlines a minor assignment for a Practical Programming with C course, focusing on array manipulation and sorting algorithms. It includes various tasks such as initializing arrays, implementing functions for summing arrays, sorting using bubble sort, merging sorted arrays, and performing binary search. Additionally, it covers set differences, copying distinct elements, and character counting in strings, with specific programming requirements and examples provided.

Uploaded by

somyaran83
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

MinorAssignment 03 2

The document outlines a minor assignment for a Practical Programming with C course, focusing on array manipulation and sorting algorithms. It includes various tasks such as initializing arrays, implementing functions for summing arrays, sorting using bubble sort, merging sorted arrays, and performing binary search. Additionally, it covers set differences, copying distinct elements, and character counting in strings, with specific programming requirements and examples provided.

Uploaded by

somyaran83
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Computer Science and Engineering

Institute of Technical Education & Research, SOA, Deemed to be University

MINOR ASSIGNMENT-03
Practical Programming with C (CSE 3544)

Publish on: 23-10-2025 Submission on: 27-10-2025


Course Outcome: CO2 Program Outcome: PO3 Learning Level: L4

Problem Statement:
Experiment with arrays for storing and processing collections of values of the same types in different appli-
cations.

Assignment Objectives:
To learn how to declare and use arrays for storing collections of values of the same type as well as to learn
how to process the elements of an array.
1. We initialize a 25-element array with the prime numbers less than 100.
int prime_lt_100[] = {2, 3, 5, 7, 11, 13, 17, Output
19, 23, 29, 31, 37,41, 43, 47, 53, 59,
61, 67, 71, 73, 79, 83, 89, 97};

Determine the array elements given in the fol-


lowing expressions;
(a) prime_lt_100[24];
(b) int i=10; prime_lt_100[i+4];
(c) prime_lt_100[prime_lt_100[2] +
prime_lt_100[0]];
(d) prime_lt_100[6]=prime_lt_100[6] +
prime_lt_100[16];

2. Design a function with prototype;


void sumarr(int a[], int b[], int r[], int size);that takes 4 parameters, two
int arrays as input arguments, 1 array as output arguments and their effective size respectively to pro-
duce a resultant array containing the sums of corresponding array elements a and b. For example, for
the three-element input arrays 5 -1 7 and 2 4 -2 , the result would be an array containing 7 3 5 .
Space for Program t Output t

1
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

3. The bubble sort is another technique for sorting an array. A bubble sort compares adjacent array
elements and exchanges their values if they are out of order. In this way, the smaller values ”bubble“
to the top of the array (toward element 0), while the larger values sink to the bottom of the array. After
the first pass of a bubble sort, the last array element is in the correct position; after the second pass
the last two elements are correct, and so on. Thus, after each pass, the unsorted portion of the array
contains one less element. Write and test a function that implements this sorting method.

Space for Program t Output t

2
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

4. You have two independent sorted arrays of size m, and n respectively, where m, n > 0. You are
required to merge the two arrays such that the merged array will be in sorted form and will contain
exactly m + n number of elements. You are not allowed to use any kind of sorting algorithm. Design
your program to meet the above given requirement.

Example 1 :

First array: 12 20 24 32 Second array: 7 8 65 105

The merged sorted array: 7 8 12 20 24 32 65 105

Example 2 :

First array: 12 20 24 Second array: 7 8 65 105

The merged sorted array: 7 8 12 20 24 65 105

Example 3 :

First array : 12 20 24 100 120 130 Second array : 17 28 105 110

The merged sorted array: 12 17 20 24 100 105 110 120 130

NOTE :
Assume the elements of the array are non-negative integers. The elements can be read from the
keyboard or can be generated randomly.

Space for Program Output t

3
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

Space for Program Output t

4
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

5. The binary search algorithm that follows may be used to search an array when the elements are in
order. The algorithm for binary search given as;

1. Let bottom be the subscript of the initial array element.


2. Let top be the subscript of the last array element.
3. Let found be false.
4. Repeat as long as bottom isn’t greater than top and the target has not been found
5. Let middle be the subscript of the element halfway between bottom and top.
6. if the element at middle is the target
7. Set found to true and index to middle.
else if the element at middle is larger than the target
8. Let top be middle - 1.
else
9. Let bottom be middle + 1.

Write and test a function binary srch that implements this algorithm for an array of integers.
When there is a large number of array elements, which function do you think is faster: binary srch
or the linear search algorithm.

Space for Program Output t

5
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

Space for Program Output t

6
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

6. Design a program to find the difference between two sets or arrays. The difference between two sets
or arrays: All the elements of the first array that don’t appear in the second array. If array p has
the elements { 1, 2, 3, 4} and array q has the elements {2, 4, 5, 6 }, then the difference between the
two arrays, p-q will be {1, 3 }.

Space for Program Output t

7
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

Space for Program Output t

8
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

7. Write a program to copy the distinct elements of an int type array to another int type array. For
example, if the input array is 4 7 7 3 2 5 5 then the output array will be 4 7 3 2 5.

Space for Program Output t

9
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

8. Construct a program to find the occurrence of the first repetitive character in a string. For example, let
the string racecar, the program should give the output as The first repititive character in the string
racecar is c.
Space for Program Output t

10
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

9. Design a program to display the count of each character in a string. For example: input string:
bintu, output: The count of each character in the string bintu is b-1, i-1, n-1, t-i, u-1.

Space for Program Output t

11
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

10. The Selection sort is a comparison-based sorting algorithm that sorts a collection by repeatedly
finding the minimum (or maximum) element and placing it in its correct position in the list. It is
generally preferred when you have to manually implement the sorting algorithm for a small amount
of dataset. Create a C program to sort an array of n elements using selection sort.

Space for Program Output t

12
Department of Computer Science and Engineering
Institute of Technical Education & Research, SOA, Deemed to be University

10. The Insertion sort is one of the simple and comparison-based sorting algorithms. The basic idea
behind the algorithm is to virtually divide the given list into two parts: a sorted part and an unsorted
part, then pick an element from the unsorted part and insert it in its place in the sorted part. It does this
till all the elements are placed in the sorted part. Develop a C program to sort an array of n elements
using insertion sort.
Space for Program Output t

13

You might also like