Assignment - 4 PF (Fall - 24)
Assignment - 4 PF (Fall - 24)
Campus
Course: Programming Fundamentals Course Code: CS 1002
Program: BS (Computer Science) Semester: Fall 2024
Due Date 31-OCT-2024 at 11:59 pm Total Marks: 80
Section: 1D Page(s): 4
Type: Assignment 4
Important Instructions:
1. You have to upload only .cpp file. Assignment in any other format (extension) will not be
accepted and will be awarded with zero marks. You have to make a zip file and upload it onto
the google classroom submission folder. For question 1, name your solution file with your roll
number, i.e., Q1_24L_1111.cpp. Similarly, you can name other questions.
2. You are not allowed to copy solutions from other students. We will check your code for
plagiarism using plagiarism checkers. If any sort of cheating is found, negative marks will be
given to all students involved.
3. Late submission of your solution is not allowed
Sample Input:
20 11 12 20 16 15 12 16 8 12 -99
Sample Output:
Distinct Element in Sorted (Increasing order) are: 8 11 12 15 16 20
Unique Element in Sorted(Decreasing order ) are: 15 11 8
Sample Input:
Enter the Array. Enter -1 to exit: 1 0 0 1 0 1 0 0 0 -1
Sample Output:
Segregated Array: 0 0 0 0 0 0 1 1 1
Question 5: [Marks: 5]
You are given an array and an index. You have to add an element at the given index of the given array
and print the new array .
Sample Input : -6 -4 0 1 4 56 589 index = 2 , element = -2
Sample Output: -6 -4 -2 0 1 4 56 589
Sample input:
Input Array: 2 5 76 53 2 89 4 76 2 2 43 53 53 2 89 76 76 -99
Sample Output:
Us: 2 5 76 53 89 4 43
Freq: 5 1 4 3 2 1 1
Sorted Us: 2 76 53 89 5 4 43
New D Array: 2 2 2 2 2 76 76 76 76 53 53 53 89 89 5 4 43
Write a program that keeps on taking input from the user until the user enters -1 (at maximum 100
values) and then sort the even index values, in increasing order and odd index values, in decreasing
order
Sample Input
INDEX 0 1 2 3 4 5 6 7
VALUE 100 10 2 3 27 9 19 13
Sample Output
INDEX 0 1 2 3 4 5 6 7
VALUE 2 13 19 10 27 9 100 3
Part-2:
Given an array of integers, print and sort the array in such a way that the first element is first maximum
and second element is first minimum and so on.
Sample Output
INDEX 0 1 2 3 4 5 6 7
VALUE 18 11 17 12 16 13 15 14