Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Military Institute of Science and Technology

Structured Programming Language Sessional - CSE 106


Practice Problems, 12th December 2022
Array (1D,2D) and String
SL Problem statement
1 Write a program in C to store elements in an array and print it.
Input :
Enter the number of elements for your array: 5
Enter the array elements:
100 2 300 1 2
Output:
You entered the following array elements:
100 2 300 1 2
2 Write a program in C to copy the elements of one array into another array.
Input :
Enter the number of elements for your array: 5
Enter the array elements:
100 2 300 1 2
Output:
The elements in array 2 are as follows:
100 2 300 1 2
3 Write a C program to put even and odd elements of an array in two separate arrays.

4 Write a program in C to find the sum of all elements of the array.


Input :
Enter the number of elements for your array: 5
Enter the array elements:
100 2 300 1 2
Output:
The sum of your array elements is : 504
5 Write a program in C to read n number of values in an array and display it in reverse order.

6 Write a program in C that will reverse an array..


Input :
Enter the number of elements for your array: 5
Enter the array elements:
100 2 300 1 2
Output:
Your array after reversing:
2 1 300 2 100
7 Write a program in C to find a value in the array.

8 Write a program in C to insert a new value at the end of an array.

9 Write a program in C to insert a new value at a particular position of an array.

10 Write a program in C to delete an element at the desired position from an array.

11 Write a C program to left rotate an array.

12 Write a C program to right rotate an array.

13 Write a program in C to find the maximum and minimum element in an array.


Input :
Enter the number of elements for your array: 5
Enter the array elements:
100 2 300 1 2
Output:
The maximum element is 300.
The minimum element is 1.

14 Write a program in C to count the total number of duplicate elements in an array.


Input :
Enter the number of elements for your array: 5
Enter the array elements:
12312
Output:
total number of duplicate elements : 2

15 Write a program in C to count the frequency of each element of an array.


Input :
Enter the number of elements for your array: 5
Enter the array elements:
99 2 99 1 2
Output:
The frequency of 99 is 2.
The frequency of 2 is 2.
The frequency of 1 is 1

16 Write a program in C to print all unique elements in an array.


Input :
Enter the number of elements for your array: 5
Enter the array elements:
12314
Output:
unique elements : 2 3 4

17 Write a program in C to find the number occurring the odd number of times in an array.

18 Write a program to sort array in ascending order

19 C Program to Read and Print a RxC Matrix, R and C must be input by the User.
Input :
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Output:
You entered the following matrix:.
12
34

20 Write a C Program to find sum and subtraction of two matrices


Input :
Inputs for matrix 1:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Inputs for matrix 2:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
11
11
Output:
The sum of the two matrices:
23
45
The diff between the two matrices:
01
23
21 Write a C Program to find the summation of each row of a matrix
Input :
Inputs for matrix 1:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Output:
The summation of row 1: 3
The summation of row 2: 7

22 Write a C program for matrix multiplication.


Input :
Inputs for matrix 1:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Inputs for matrix 2:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
11
11
Output:
Matrix multiplication result:
33
77

23 Write a C program to print the right diagonal elements of a matrix.


Input :
Inputs for matrix 1:
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Output:
The elements of the diagonal are:
14
24 Write a C program to print the left diagonal elements of a matrix.
Input :
Inputs for matrix :
Enter the value of R: 2
Enter the value of C : 2
Enter the matrix elements:
12
34
Output:
The elements of the diagonal are:
23
25 Write a C program to print the lower triangular of a matrix:
Input :
Inputs for matrix :
Enter the value of R: 3
Enter the value of C : 3
Enter the matrix elements:
123
456
789
Output:
lower triangular of a matrix
1
45
789

26 Write a C program to print the transpose of a matrix:


Input :
Inputs for matrix :
Enter the value of R: 3
Enter the value of C : 3
Enter the matrix elements:
123
456
789
Output:
lower triangular of a matrix
147
258
369
27 Write a C program to take a string as input. Then print the string along with its length .
Input:
Input String: Hello
Output:
Output String: Hello 5
28 Write a C program that will check whether two strings are the same or not.
Input:
1st String: Hello
2nd String: World
Output:
Hello and World are not the same.
29 Write a C program to take two strings as input. Then concatenate the two strings.
Input:
1st String: Hello
2nd String: World
Output:
Concatenated String: Hello World
30 Write a program in C that will reverse a string.
Input :
Input String: Hello
Output:
Output String: olleH
31 Write a C program to take a string as input. Then convert each character of the string to uppercase.
Input:
Input String: Hello World
Output:
Output String: HELLO WORLD
32 Write a C program to find out how many words are present in a string.
Input :
Input String: Hello World
Output:
There are 2 words.
33 Write a C program to find the frequency of each character present in a string.
Input :
Input String: hello
Output:
e appears 2 time(s).
h appears 1 time(s).
l appears 2 times(s).
o appears 1 time(s).

34 Write a C program to find out if a string is a substring of another string or not.


Input :
Input String1: Hello World
Input String2: orl
Output:
orl is a substring of Hello World

You might also like