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

Module 3

The document contains a list of programming tasks in C and C++ that cover various topics, including sorting arrays, matrix operations, string manipulation, and calculating statistics. Each task is numbered and includes specific requirements, such as finding medians, counting duplicates, and handling user input. Additionally, there are optional questions that further explore similar concepts or introduce new challenges.

Uploaded by

namanlodha616
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 3

The document contains a list of programming tasks in C and C++ that cover various topics, including sorting arrays, matrix operations, string manipulation, and calculating statistics. Each task is numbered and includes specific requirements, such as finding medians, counting duplicates, and handling user input. Additionally, there are optional questions that further explore similar concepts or introduce new challenges.

Uploaded by

namanlodha616
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SR NO Question 1 Question 2 (Optional)

Write a program in C to accept n elements from the user, sort those elements and
1
find its median and display it.
Write a program to sort a set of names stored in an array in
2
alphabetical order.
Write a program that generates a square matrix of size n x n (1 ≤ n ≤ 20), where each
element is an integer. Use nested loops and the following rules to fill the matrix:
Write a program in C++ to perform the following operations on a 2D matrix of integers (size
The diagonal elements (from top-left to bottom-right) should be filled with the 𝑁× 𝑀, where 1≤𝑁,𝑀≤10):
square of their 1-based index (e.g., 1, 4, 9, ...). Take input for the matrix and display it.
3 For elements above the diagonal, assign the value as (i + j), where i and j are the Transpose the matrix in place (if 𝑁=𝑀), or create a new matrix for the transpose (if 𝑁≠𝑀).
0-based row and column indices. Sort each row of the matrix in ascending order.
For elements below the diagonal, assign the value as (i * j). Calculate the sum of all diagonal elements (both primary and secondary diagonals).
If any value is divisible by 7, skip assigning it and replace it with -1. Your program should handle edge cases like non-square matrices and empty matrices.
Finally, display the matrix with proper formatting, and count how many -1 values are
present in the matrix.
write C program using array. the X and Y coordinates of 10 different points are
entered
4 through the keyboard. Write a program to find the distance of
last point from the first point (sum of distance between
consecutive points).
Write a program to rotate an array to the left by a given number of positions.
5 Write a program in C to count a total number of duplicate elements in an array.

Write a C program to insert the character/word in any desired location in a string. Input: enter the string: Fun to
Write a C program that checks 2 elements in the array such that the difference learn C Programming.
6 between them is the largest. Input array[] = {10, 15, 90, 200, 110} and output: enter the word to insert: PIC
Maximum difference between 10 and 200 is 190. enter the position you like to insert:4
Output : the string after modification is : Fun to learn PIC C Programming.
Write a program in C to generate a square matrix of size n x n (where 1≤n≤20) based on the following rules:
• Diagonal elements (from top-left to bottom-right) should contain the cube of their index (e.g., 1, 8, 27, ...).
Write a program in C to accept n integers from the user, sort them in ascending • Elements above the diagonal should be the sum of their row and column indices.
7 order, and find the median. Display the sorted array and the median value. Ensure • Elements below the diagonal should contain the absolute difference between their row and column indices.
your program works for both odd and even values of n. • Replace any element divisible by 5 with -1.
Display the matrix in a well-formatted style and count how many -1 values are present.

Write a C program that takes an array and an integer element as input, and counts Write a C program that rotates the elements of an array to the left by N positions. For example, if the array is {1,
8
how many times the element appears in the array. 2, 3, 4, 5} and N = 2, the result should be {3, 4, 5, 1, 2}.
Twenty-five numbers are entered from the keyboard into an
array. The number to be searched is entered through the A 6 x 6 matrix is entered through the keyboard and stored in a
9 keyboard by the user. Write a program to find if the number to 2-dimensional array mat[7][7]. Write a program to obtain the
be searched is present in the array and if it is present, display Determinant values of this matrix.
the number of times it appears in the array.
10 Write a program to find the sum and average of elements in a one-dimensional array. Write a program to find the largest element in a two-dimensional array.
Write a program in C to accept two strings from the user and check if they are Write a program in C to accept an array of integers and find the largest and smallest elements in the array.
11 anagrams. Two strings are anagrams if they contain the same characters in any Display both the largest and smallest elements along with their positions in the array.
order, ignoring spaces and case sensitivity.
In a small company, there are 5 salesmen. Each salesman is supposed to sell 3
12 products a,b,c. Write a program using two dimensional array to print 1) the total
sales by each salesman and 2) total sales of each item.
SR NO Question 1 Question 2 (Optional)
Write a C program that takes a string and two integers (n1, n2). Now reverse the
sequence of characters in the string between n1 and n2. Sample Date:
13
("abcdxyabcd", 5, 6) -> "abcdyxabcd"
("Exercises", 1, 3) -> "exErcises"
14 Write a program in C to count the total number of duplicate elements in an array. Write a program in C to merge two arrays of the same size sorted in descending order.
Write a C program to simulate the sorting of a deck of 52 playing cards. The
program should first sort the cards based on their suits (e.g., Spades, Hearts,
15
Diamonds, Clubs) and then within each suit, sort the cards by their rank (Ace, 2, 3, ...,
King).
Thirty numbers are entered from the keyboard into an array. Write a program to find
16 out how many of them are positive, how many are negative, how many are even and
how many odd.
17 Write a C program to count how many times each element appears in an array Write a C program to perform matrix multiplication of two 2*2 matrices
Implement a program to rotate a one-dimensional array of size N to the right by K
positions.
Example:
18
Input: arr = {1, 2, 3, 4, 5}, K = 2
Output: {4, 5, 1, 2, 3}
19 Write a program in C to check whether a given matrix is an identity matrix.
Design a C program to categorize a student's grade based on their percentage:

Use an else-if ladder to categorize percentages into grades (e.g., 90-100: A, 75-89: B,
20 50-74: C, <50: Fail).
Include a do-while loop to allow the user to input grades for multiple students.
Use a break statement to terminate the loop when a user enters a negative
percentage.
Write a program to input a sentence (character array) of at most 100 characters and Write a program to input a 2D array of size
perform the following: 𝑁×𝑀 (where 1≤𝑁,𝑀≤10) and display its elements in spiral order (clockwise). For example, the input:
1 2 3
Count the frequency of each vowel (case insensitive). 4 5 6
21 Identify the most frequently occurring character in the sentence. 7 8 9
Replace every vowel in the sentence with the next vowel in cyclic order (e.g., 'a' → 'e', Should output:
'e' → 'i', ..., 'u' → 'a'). 1, 2, 3, 6, 9, 8, 7, 4, 5.
Reverse the words in the sentence while preserving their order (e.g., "Hello World"
becomes "olleH dlroW"). Ensure that your program works for rectangular matrices as well.
Write a program in C to make such a pattern like a right angle triangle with a number
which will repeat a number in a row.
1
22
22
333
4444
Write a program to print the following pattern of numbers:
1
23
23
456
7 8 9 10
11 12 13 14 15
SR NO Question 1 Question 2 (Optional)
Write a C program to take an MxN matrix as input and find the row with the highest Write a program that checks if two strings are anagrams (i.e., rearrangement of the same characters).
24 sum.
Example: "listen" and "silent" are anagrams.
In a class there are 10 students.Each student is supposed to appear in 3 tests.write
a program using two dimentional arrays to print.1)the marks obtasined bt each
25 student in diffenet subject. 2)Total amrks and average obtained by each student. write a program to read sentence .then count the number of words in the sentence
3)store the average of each student in a separate iD array so that it can be used to
calculate the class average.
Program to print the multiplication table as given below:
1 2 3 4 5
____________________________________________________
1 1 2 3 4 5
2 2 4 6 8 10
3 3 6 9 12
26 4 Write a C program to compare two strings without using any string function.
5
6
7
8
9
10
27 Write a program to find the frequency of each element in an array. Write a program to concatenate two strings using arrays.

You might also like