0% found this document useful (0 votes)
5 views9 pages

C Extra Program List

The document is a list of programming problems for a C course in the Department of Computer Science & Engineering for the academic year 2023-24. It includes various tasks such as finding sums, checking for palindromes, sorting arrays, and converting number systems, among others. Each problem is designed to enhance programming skills and understanding of algorithms.
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)
5 views9 pages

C Extra Program List

The document is a list of programming problems for a C course in the Department of Computer Science & Engineering for the academic year 2023-24. It includes various tasks such as finding sums, checking for palindromes, sorting arrays, and converting number systems, among others. Each problem is designed to enhance programming skills and understanding of algorithms.
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/ 9

Department of Computer Science & Engineering

Academic Year 2023-24


C program List

Sr. Problem Definition


1 WAP to find a sum of even number into 1D array.
2 WAP to find whether string is palindrome or not.
3 WAP to find a Factor of a given number (iterative and recursive)
4 WAP to find a factorial of a given integer (iterative and recursive)
5 WAP to find a summation of a digit of a given number. (Iterative and recursive)
6 Print a following pattern1
12
123
1234

7 WAP to find a Fibonacci series up to n terms (n is entered by user) (iterative and recursive)
8 WAP to find a total odd and total even digit of a given number.
9 WAP to find whether a number is Odd or Even without using a % operator.
10 WAP to find a prime number between range (range should be entered by user).
11 WAP to find weather given number is Armstrong number is not.
12 WAP to find Max, Min, Average of n numbers, n should be taken from user and all n value should
be taken from user (Note that you are not allowed to use an array for this)
13 WAP to find a Multiplication of 2 Matrix (dimension and value should be entered by user)
14 WAP to calculate an angle between hour and minute hand. (Hours and minutes should betaken from
user).
15 WAP to convert a Decimal number to BCD.
16 WAP to sort an Array using Bubble sort.
17 WAP to sort an Array using insertion sort.
18 WAP to sort an Array using Selection sort.
19 WAP to sort an Array using Bucket sort.
20 WAP to find a power a^b (without using power and multiplication operation).
21 WAP to sort an Array using Radix sort.
22 Print a following pattern
********* *********
******* **** ****
***** *** ***
*** ** **
* * *
23 WAP to enter an element at specific position into array. (Do not take a new array)
24 WAP to delete an element from array specified by user. if element is not found print a
message “Element is not found” (do not take a new array).
25 WAP to check weather number is present in array or not (using recursion only) and the
function’s syntax is given below
Int isInArray(int a[],int m);
Where int a[] is Array of integer and m is element to be searched.
26 WAP to convert a Binary to Decimal.
27 WAP to find a quotient and reminder of 2 number (bigger number should be divided by lower
number) and you are not allowed to use a division and quotient operator.
28 WAP to convert a Decimal to Binary.
29 Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in
the result must appear as many times as it shows in both arrays and you may
return the result in sorted order.
30 Given an array, rotate the array to the right by k steps, where k is non-negative.Example
1:
1|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

Input: nums = [1,2,3,4,5,6,7], k = 3


Output: [5,6,7,1,2,3,4]
Explanation:
rotate 1 step to the right: [7,1,2,3,4,5,6] rotate 2
steps to the right: [6,7,1,2,3,4,5]
rotate 3 steps to the right: [5,6,7,1,2,3,4]
31 Given an array nums with n integers, your task is to check if it could become non-decreasingby
modifying at most one
Input: nums = [4,2,3] Output:
true
Explanation: You could modify the first 4 to 1 to get a non-decreasing array.
32 You are given an integer num. Rearrange the digits of num such that its value is minimizedand it
does not contain any leading zeros.
Return the rearranged number with minimal value.
Note that the sign of the number does not change after rearranging the digits.Input:
num = 310
Output: 103
Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301,
310.
The arrangement with the smallest value that does not contain any leading zeros is 103.
33 Given an array of N integers, and an integer K, find the number of pairs of elements in the array
whose sum is equal to K.
e.g. Input:
N = 4, K = 6
arr[] = {1, 5, 7, 1}
Output: 2
Explanation:
arr[0] + arr[1] = 1 + 5 = 6
and arr[1] + arr[3] = 5 + 1 = 6.
34 WAP to convert an Octal into hexa-decimal.
35 WAP to convert a hexa-decimal to Octal.
36 WAP to Convert a Decimal to Octal and Vice versa.
37 WAP to Convert a Decimal to Hexa-decimal and vice versa.
38 Write a program to take 2 numbers from user and find out the distance between them. (How to
compute distance: If number is 10 and 18 then 10 in binary 1010 and 18 in binary is 10010 and
distance is 2 means total number of bits that needs to be changed when 10 is
converted into 18 or 18 is converted into 10, do not convert the number into binary)
39 You have n super washing machines on a line. Initially, each washing machine has some dresses or is
empty.
For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dressof each
washing machine to one of its adjacent washing machines at the same time.
Given an integer array machine representing the number of dresses in each washing machinefrom left
to right on the line, return the minimum number of moves to make all the washing machines have the
same number of dresses. If it is not possible to do it, return -1.
Input: machines = [1,0,5] Output:
3
Explanation:
1st move: 1 0 <-- 5 => 1 1 4
2nd move: 1 <-- 1 <-- 4 => 2 1 3
3rd move: 2 1 <-- 3 => 2 2 2Input:
machines = [0,3,0]
Output: 2
Explanation:
1st move: 0 <-- 3 0 => 1 2 0
2|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

2nd move: 1 2 --> 0


=> 1 1 1
40 You are given several boxes with different colors represented by different positive numbers.You may
experience several rounds to remove boxes until there is no box left. Each time youcan choose some
continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k
points.
Return the maximum points you can get. Input:
boxes = [1,3,2,2,2,3,4,3,1]
Output: 23
Explanation:
[1, 3, 2, 2, 2, 3, 4, 3, 1]
----> [1, 3, 3, 4, 3, 1] (3*3=9 points)
----> [1, 3, 3, 3, 1] (1*1=1 points)
----> [1, 1] (3*3=9 points)
----> [] (2*2=4 points)
41 Implement atoi function with the help of pointer
42 Implement itoa function with the help of pointer
43 Given an array of integers nums and an integer target, return indices of the two numbers such that
they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same
element twice.

You can return the answer in any order.


Example 1:

Input: nums = [2,7,11,15], target = 9


Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
44 Convert a roman number into Decimal number.
45 Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase,
typically using all the original letters exactly once.

Example 1:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Example 2:

Input: strs = [""]


Output: [[""]]

Example 3:

Input: strs = ["a"]


Output: [["a"]]
46 Chef is standing at coordinate A while Chefina is standing at coordinate B.

In one step, Chef can increase or decrease his coordinate by at most K.

Determine the minimum number of steps required by Chef to reach Chefina.

Input Format
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of three integers X,Y, and K, the initial coordinate of Chef, the initial
coordinate of Chefina and the maximum number of coordinates Chef can move in one step.
Output Format
3|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

For each test case, output the minimum number of steps required by Chef to reach Chefina.
47 Chef's dog binary hears frequencies starting from 67 Hertz to 45000 Hertz (both inclusive).

If Chef's commands have a frequency of XX Hertz, find whether binary can hear them or not.

Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of a single integer XX - the frequency of Chef's commands in Hertz.

Output Format
For each test case, output on a new line YES, if binary can hear Chef's commands. Otherwise, print
NO.

The output is case-insensitive. Thus, the strings YES, yes, yeS, and Yes are all considered the same.
48 Each contest - there are approximately 1500 - 2000 users who participate for the 1st time and get
rated.

The Chef wanted to tell new users some tricks for their 1st contest:

Before the contest - you don’t have any rating. So even if you make a single submission - you will
become part of the contest rank list and you will get a rating.
If you want your rating to increase - give the entire 3 hours to the contest & don’t quit! If you keep
trying till the end, and the more time you get, the more problems you can solve. That means larger
rating increases!
Do not ask your friends for their code. If you copy paste their code, you will get caught during
plagiarism checks and your rating will be reduced by 275 points, along with a permanent black mark
on your profile.
Now to the problem:

In a contest where N new users visited the contest,

A user just saw the problems and didn’t make any submissions and hence won’t get any rating.
B users who made a submission but could not solve any problem correctly. Thus, after the contest,
they will get a rating in the range 800−1000.
Everyone else could correctly solve at least 11 problems. Thus, they will get a rating strictly greater
than 1000 after the contest.
You need to output the number of new users in the contest who, after the contest, will get a rating
and also the number of new users who will get a rating strictly greater than 1000.

Input Format
Each input file contains of a single line, with three integers, A and B - the number of new users, the
number of users who just saw the problem and didn't make any submission, and the number of users
who made a submission but could not solve any problem correctly.
Output Format
Output two integers separated by a space in a single line - the number of new users who will get a
rating at the end of the contest and the number of new users who will get a rating higher than 1000.
49 In Chef Land, human brain speed is measured in bits per second (bps). Chef has a threshold limit of
XX bits per second above which his calculations are prone to errors. If Chef is currently working at YY
bits per second, is he prone to errors?

If Chef is prone to errors print YES, otherwise print NO.

Input Format
The only line of input contains two space separated integers X and Y — the threshold limit and the
rate at which Chef is currently working at.

Output Format
If Chef is prone to errors print YES, otherwise print NO.

4|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

You may print each character of the string in uppercase or lowercase (for example, the strings yes,
Yes, yEs, and YES will all be treated as identical).
50 Problem
Chef's son wants to go on a roller coaster ride. The height of Chef's son is X inches while the
minimum height required to go on the ride is H inches. Determine whether he can go on the ride or
not.

Input Format
The first line contains a single integer T - the number of test cases. Then the test cases follow.
The first and only line of each test case contains two integers X and H - the height of Chef's son and
the minimum height required for the ride respectively.

Output Format
For each test case, output in a single line, YES if Chef's son can go on the ride. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes
will be considered identical)
51 Chef's computer has NN GB of free space. He wants to save X files, each of size 1 GB and Y files, each
of size 2 GB on his computer. Will he be able to do so?

Chef can save all the files on his computer only if the total size of the files is less than or equal to the
space available on his computer.

Input Format
The first line contains an integer TT, denoting the number of test cases. The T test cases then follow:
The first and only line of each test case contains three integers N,,X,Y, denoting the free-space in
computer, the number of 1 and 2 GB files respectively.

Output Format
For each test case, print YES if Chef is able to save the files and NO otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings yEs,
yes, Yes and YES will all be treated as identical).
52 Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

An interleaving of two strings s and t is a configuration where s and t are divided into n and m
substrings
respectively, such that:

s = s1 + s2 + ... + sn
t = t1 + t2 + ... + tm
|n - m| <= 1
The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
Note: a + b is the concatenation of strings a and b.
53 Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of
the same color are adjacent, with the colors in the order red, white, and blue.

We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

You must solve this problem without using the library's sort function.

Example 1:

Input: nums = [2,0,2,1,1,0]


Output: [0,0,1,1,2,2]
54 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the
following rules:

Each row must contain the digits 1-9 without repetition.


5|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

Each column must contain the digits 1-9 without repetition.


Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.

Note:
A Sudoku board (partially filled) could be valid but is not necessarily solvable.
Only the filled cells need to be validated according to the mentioned rules.

Input: board =
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
Output: true
55 Given a sorted array of distinct integers and a target value, return the index if the target is found. If
not, return the index where it would be if it were inserted in order.

Input: nums = [1,3,5,6], target = 5


Output: 2

Input: nums = [1,3,5,6], target = 2


Output: 1
56 Given an array of distinct integers candidates and a target integer target, return a list of all unique
combinations of candidates where the chosen numbers sum to target. You may return the
combinations in any order.

The same number may be chosen from candidates an unlimited number of times. Two combinations
are unique if the
frequency
of at least one of the chosen numbers is different.

The test cases are generated such that the number of unique combinations that sum up to target is
less than 150 combinations for the given input.

Input: candidates = [2,3,6,7], target = 7


Output: [[2,2,3],[7]]
Explanation:
2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.
7 is a candidate, and 7 = 7.
These are the only two combinations.
57 You are given a set of points in the 2D plane. You start at the point with the least X and greatest Y
value, and end at the point with the greatest X and least Y value. The rule for movement is that you
can not move to a point with a lesser X value as compared to the X value of the point you are on. Also
for points having the same X value, you need to visit the point with the greatest Y value before
visiting the next point with the same X value. So, if there are 2 points: (0,4 and 4,0) we would start
with (0,4) - i.e. least X takes precedence over greatest Y. You need to visit every point in the plane.

Input
You will be given an integer t(1<=t<=20) representing the number of test cases. A new line follows;
after which the t test cases are given. Each test case starts with a blank line followed by an integer
n(2<=n<=100000), which represents the number of points to follow. This is followed by a new line.
Then follow the n points, each being a pair of integers separated by a single space; followed by a new
line. The X and Y coordinates of each point will be between 0 and 10000 both inclusive.

Output
6|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

For each test case, print the total distance traveled by you from start to finish; keeping in mind the
rules mentioned above, correct to 2 decimal places. The result for each test case must be on a new
line.
58 Given an unsorted integer array nums, return the smallest missing positive integer.
Input: nums = [1,2,0]
Output: 3
Explanation: The numbers in the range [1,2] are all in the array.
59 Given n non-negative integers representing an elevation map where the width of each bar is 1,
compute how much water it can trap after raining.

Example 1:

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]


Output: 6
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1].
In this case, 6 units of rain water (blue section) are being trapped.
Example 2:

Input: height = [4,2,0,3,2,5]


Output: 9
60 You are transporting some boxes through a tunnel, where each box is a parallelepiped, and is
characterized by its length, width and height.

The height of the tunnel 41 feet and the width can be assumed to be infinite. A box can be carried
through the tunnel only if its height is strictly less than the tunnel's height. Find the volume of each
box that can be successfully transported to the other end of the tunnel. Note: Boxes cannot be
rotated.

Input Format

The first line contains a single integer n, denoting the number of boxes.
N lines follow with three integers on each separated by single spaces –length width and height, and
which are length, width and height in feet of the i-th box.

Output Format
For every box from the input which has a height lesser than 41 feet, print its volume in a separate
line.
61 Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go
outside the signed 32-bit integer range [-231, 231 - 1], then return 0
62 Print a Pascal Triangle
63 Given a triangle array, return the minimum path sum from top to bottom.

For each step, you may move to an adjacent number of the row below. More formally, if you are on
index i on the current row, you may move to either index i or index i + 1 on the next row.

Example 1:

Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]


Output: 11
7|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

Explanation: The triangle looks like:


2
34
657
4183
The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
Example 2:

Input: triangle = [[-10]]


Output: -10
64 You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different
day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit,
return 0.

Example 1:

Input: prices = [7,1,5,3,6,4]


Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
65 Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-
separated sequence of one or more dictionary words.

Note that the same word in the dictionary may be reused multiple times in the segmentation.

Example 1:

Input: s = "leetcode", wordDict = ["leet","code"]


Output: true
Explanation: Return true because "leetcode" can be segmented as "leet code".
66 Print the source code of program and output
67 WAP to sort a strings into Lexicographical order.
68 Chang's new maths teacher is very enthusiastic about making sure that students understand the
concept rather than remembering it. On her first day at teaching, she gives an assignment to all the
students to test their potential. Chang wants to demonstrate that he understands the concept ra ther
than rote learning. Help Chang in doing this by solving the hardest problem in the assignment. The
problem is written as follows.

A perfect function is defined in the following manner.

F(x, y) = x2 + y for 1 ≤ x ≤ A, 1 ≤ y ≤ B
F(x, y) = 2 otherwise
Find the number of integral pairs (x, y) such that F(x, y) is a perfect square.

Input
First and the only line of the input contains two single space separated integers A and B.

Output
Output a single integer indicating the output to the only test case.
69 You are given a 2 × N grid (2 rows, N columns) consisting of lower case English characters (i.e. from
8|Pa ge
Department of Computer Science & Engineering
Academic Year 2023-24
C program List

'a' to 'z'). Two cells are said to be adjacent if they share a side with each other.

The score of such a grid is defined to be the number of unordered pairs of adjacent cells, which have
the same character in them.

You want to rearrange the letters of the grid in such a way that the score is maximized and print the
new rearranged grid. If there are multiple solutions, you can print any.

Input
The first line of the input contains an integer T denoting the number of test cases. The description of
T test cases follow.

The first line of each test case contains an integer N, denoting the number of columns in the grid.

Each of the next two lines contains a string consisting of N lowercase English characters, describing
the first and the second rows of the grid respectively.

Output
For each test case, output two lines, each containing a string of length N. These should describe the
first and the second rows of the rearranged grid.
70 Matrix Multiplication of Different Size.

9|Pa ge

You might also like