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

array probs

The document contains lecture notes for a course on Problem Solving with C, focusing on arrays. It outlines course objectives and outcomes, including skills in algorithmic solutions, sorting, searching, and text processing using C. Additionally, it provides a series of programming exercises categorized by difficulty levels to reinforce learning.
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)
4 views

array probs

The document contains lecture notes for a course on Problem Solving with C, focusing on arrays. It outlines course objectives and outcomes, including skills in algorithmic solutions, sorting, searching, and text processing using C. Additionally, it provides a series of programming exercises categorized by difficulty levels to reinforce learning.
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
You are on page 1/ 5

Department of Computer Science and Engineering,

PES University, Bangalore, India


Lecture Notes
Problem Solving With C
UE24CS151B

Lecture #3
Problem Solving using Arrays

By,
Prof. Sindhu R Pai,
Theory Anchor, Feb-May, 2025
Assistant Professor
Dept. of CSE, PESU

Many Thanks to
Dr. Shylaja S S (Director, CCBD and CDSAML Research Center, PES University)
Prof. Nitin V Pujari (Dean, Internal Quality Assurance Cell, PES University)
Feb – May,2025

Unit #: 2
Unit Name: Counting, Sorting and Searching
Topic: Problem Solving using Arrays

Course objectives: The objective(s) of this course is to make students


 Acquire knowledge on how to solve relevant and logical problems using computing
Machine.
 Map algorithmic solutions to relevant features of C programming language constructs.
 Gain knowledge about C constructs and its associated ecosystem.
 Appreciate and gain knowledge about the issues with C Standards and it’s respective
behaviours.

Course outcomes: At the end of the course, the student will be able to:
 Understand and Apply algorithmic solutions to counting problems using appropriate C
Constructs.
 Understand, Analyze and Apply sorting and Searching techniques.
 Understand, Analyze and Apply text processing and string manipulation methods using
Arrays, Pointers and functions.
 Understand user defined type creation and implement the same using C structures,
unions and other ways by reading and storing the data in secondary systems which
are portable.

Sindhu R Pai
Theory Anchor, Feb - May, 2025
Dept. of CSE,
PES University

Department of CSE, PESU 2


Feb – May,2025

Solve the below programs using C Arrays.

Link for Solution:


https://drive.google.com/file/d/1ki5RyURIrY8OxB04OEb9bUPR2606Rv3D/view?usp=drive_link

Level-1: Banana
1. Given the array, build an application to find the sum of all elements of the array.
int arr1[ ] = {5, 10, 15, 20, 25};

2. Seven friends decided to have a race in the park. After the race, they recorded their
running times in seconds: [12, 15, 10, 18, 9, 14, 11]
Implement the logic in C to find out the running time for a fastest runner?

3. Develop a C Application to Count the number of elements in the given array and
print the count.
int arr1[ ] = {5, 10, 15, 20, 25, 12, 99, 56, 33, 29, 10};

4. Build an application in C to find the count of even and odd integers in a given array.
int arr1[ ] = {5, 10, 15, 20, 25, 12, 99, 56, 33, 29, 10};

5. Given an array of integers, count how many numbers are prime.


int arr[] = {2, 3, 4, 5, 10, 17, 19, 22, 25};
Expected output: Count of prime numbers: 5

6. Given an array, count how many numbers are positive and how many are negative.
int arr[] = {-5, 10, -15, 20, -25, 12, -99, 56, 33, -29, 10};
Expected output:
Count of positive numbers: 6
Count of negative numbers: 5

7. Given an array and a number X, count how many numbers are greater than X and print
them.
int arr[] = {5, 10, 15, 20, 25, 12, 99, 56, 33, 29, 10};
int x = 20;
Expected output:
Count of numbers greater than 20: 5
Numbers greater then 20 are - 25, 99, 56, 33, 29

8. Emma wanted to find out which stickers were repeated in her collection. She carefully
arranged all the stickers and noted down their numbers in sequence:
[12, 25, 30, 12, 45, 60, 25, 30, 75, 90, 45]. Now, she faced a challenge: Can you figure
out how many stickers appeared more than once?

Department of CSE, PESU 3


Feb – May,2025

9. Given an array, count how many numbers end with a specific digit X(e.g., 5).
int arr[] = {5, 15, 25, 30, 45, 50, 60, 75};
X=5
Expected output: Count of numbers ending with 5: 5

10. A young programmer, Alex, found a magical book that contained an ancient spell to
reverse time. The spell was hidden in a sequence of numbers, and to unlock its power,
Alex needed to reverse the sequence. Help Alex to decode the spell by implementing
an application using C.

Level-2: Orange
11. Write a program that checks and prints if the given array of integers is a Palindrome
or not. Receive all inputs from the user.
[1,3,2,2,3,1] -> Palindrome
[1,3,2,3,1] -> Palindrome
[10,32,25,32,10] -> Palindrome
[1,4,6,3,1] ->Not A Palindrome

12. Write a Program to create an Array of n integers and check if the array is “Really
Sorted” , “Sorted”,“Not Sorted”
Example #1 : [1,2,5,7,10] -> Really Sorted
Example #2 : [1,2,5,5,10] -> Sorted
Example #3 : [1,12,5,45,10] -> Not Sorted

13. Given the array of n integers, count the number of Unique Elements in the
Array(not repeated elements) and store these elements in a new array.
int arr[] = {5, 7, 3, 4, 5, 6, 8, 9, 10, 3};
Expected Input and Output:
Given Array -> [5,7,3,4,5,6,8,9,10,3]
New array -> [7,4,6,8,9,10]
Number of Unique Elements -> 6

14. Write a C Program that should rotate the given array by N positions at the left.
Expected Input and Output:
Input: [5,4,7,3]
If N = 2
After left Rotation -> [7,3,5,4]

15. Given a list of N integers, representing height of mountains. Find the height of the
tallest mountain and the second tallest mountain. Handle edge cases by displaying
appropriate messages.
Example #1 : [4,7,6,3,1]
7 -> height of the tallest mountain
6 -> height of the second tallest mountain

Department of CSE, PESU 4


Feb – May,2025

Level-3: Jackfruit
16. Write a C program to input N integers to the array and find the median of sorted array
of integers. Median is calculated using the below formulae:

17. Abhi is a salesman. He was given two types of candies, which he is selling
in N different cities. In his excitement, Abhi wrote down the prices of both the candies
on the same page and in random order instead of writing them on different pages. Now
he is asking for your help to find out if the prices he wrote are valid or not. You are
given an array A of size 2N. Find out whether it is possible to split A into two arrays,
each of length N, such that both arrays consist of distinct elements.

18. Given an array A of size N, your task is to find and print all the peak elements in the
array. A peak element is one that is strictly greater than its neighboring elements. For
the first and last elements, only consider their single adjacent element. If no peak
element exists in the array, print -1.

19. Develop an application that calculates and prints the largest sum of two Adjacent
Elements in the array. Display appropriate message for handling the edge cases.
Example #1 : [1,4,3,7,1] ->10
Example #2 : [5,7,1,5,2] ->12

20. Our James has some students in his coding class who are practicing problems. Given
the difficulty of the problems that the students have solved in order, help
the James identify if they are solving them in non-decreasing order of difficulty. Non-
decreasing means that the values in an array is either increasing or remaining the
same, but not decreasing. That is, the students should not solve a problem with
difficulty d1, and then later a problem with difficulty d2, where d1>d2. Output “Yes” if
the problems are attempted in non-decreasing order of difficulty rating and “No” if not.

Happy Coding using Arrays!!!

Department of CSE, PESU 5

You might also like