You are on page 1of 2

North South University CSE115,

Spring 2022, Due date: 30th April, 2022.

1) Write a program in C to display all unique elements (elements that occur only once) in an array.
2)Write a program in C to count the total number of duplicate elements (elements which occur twice) in
an array.
Test Data:
Input the number of elements to be stored in the array :5
Input 5 elements in the array:
element - 0: 9
element - 1: 15
element - 2: 3
element - 3: 15
element - 4: 9
Expected Output:
Total number of duplicate elements found in the array is: 2

3) Write a program in C with a function that will reverse the elements in an array.
Function Prototype: void RevArr (int arr[], int size);

Array index 0 1 2 3 4 5 6
Sample input: 5 10 12 9 100 200 500
Expected output 500 200 100 9 12 10 5

4)Write a program in C to rotate an array by N positions. (N to be given by user)


Function prototype: void shiftArr1Pos (int arr1[], int arrSize)
void arr1Rotate (int arr1[], int arrSize, int rotFrom)
(The first function shiftArr1Pos () should only contain the code to shift elements in the array by one
position)
Expected Output:
The given array is: 0 3 6 9 12 14 18 20 22 25 27
From 4th position the values of the array are: 12 14 18 20 22 25 27
Before 4th position the values of the array are: 0 3 6 9
After rotating from 4th position the array is: 12 14 18 20 22 25 27 0 3 6 9

(Try at home: solve the same problem using pointer notation)

5)Write a program in C to remove all characters in String Except Alphabets.


Test Data:
Input the string: coronaupdate2news.co3m
Expected Output: After removing the Output String: coronaupdatenewscom
6) Write a program with the function void getridofshift(char str[], char ch) that will generate a modified
string with all occurrence of a particular character (provided by the user) removed from the string.
Input String: betty bought a bit of butter
Character to remove: b
Output string: etty ought a it of utter

For your better understanding:


Diagrammatically, char array before modification
A 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
i 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
b e t t y b o u g h t a b i t o f b u t t e r

Diagrammatically, char array after modification


A 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2
i 0 1 2 3 4 5 6 7 8 9 0 1 2 3
e t t y o u g h t a i t o f u t t e r
Ai: Array index

7)Implement the following function which finds the largest element in an array and doubles it (use
pointer)
Function Prototype: void max (int *p, int size);
Display the modified array from main();

8) Create a structure called Patient with the following members: Registration_Number, Name, Age,
Gender, Contact Number, Address, Corona_status (Corona_status indicates whether the patient had
corona in the past or not. You may implement this member as integer variable with 0 or 1 stored in it
(concept of flag)).

Assume that there will not be more than 50 patients in the hospital on a single day. Since people who
had corona in the past might have complications, so in order to visit a physician, each patient need to
inform whether he/she had corona in the past or not. Populate the array with information of n number
of patients (the number n is to be provided by user).

[You may write a menu driven program or you may make function calls from main (). You are
recommended not to declare the array of structure as global variable.]

a)Write a function to display names and registration number of all patients (who had corona in the past)
in the n number of patients in the array.
b) Write a function to delete patient information given a name by the user. [Consider all names are
unique].
c) Write a function to modify contact number and address member of a record given the registration
number of a patient. Save the information in a .txt file.

You might also like