Sei sulla pagina 1di 4

Practice Questions:

1) Program to check if two given matrices are identical


2) Program to print the given 2D Array or Matrix in spiral form
Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Output:
1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
3) A n-by-n matrix of 0’s and 1’s is given, where all 1’s in each row come before
all 0’s, find the most efficient way to return the row with the maximum number
of 0’s.
4) Write a program sorting for an array of 10 double get from user
5) Write a program to find the GCD of two Integers.
6) Write a program to remove all vowels from a string.
7) Write a program to return a sorted array from two unsorted array.
8) Write a program to swap two numbers without using third variable,
This question can be solved using three ways as follows:
1) Using + and – 2) Using * and / 3) Using Bitwise XOR
9: Write a program to do linear search in array which consists of 10 labs’
computer counts then modify the computer count as 45 which are all contains
less than 30
10: Rotate array left, array element should get from user
11: Write a program to find out sum of digits of given number.
12: Write a program to print Fibonacci series of given range.
13: Write a program to print Non-prime numbers for given Two range
14: Trapezium Pattern in C
If N = 4
1*2*3*4*17*18*19*20
5*6*7*14*15*16
8*9*12*13
10*11
If n = 5
1*2*3*4*5*26*27*28*29*30
6*7*8*9*22*23*24*25
10*11*12*19*20*21
13*14*17*18
15*16
If N = 2
1*2*5*6
3*4
15: Find No of frequency of given digits from given number
16: Given a positive integer num, write a program to print all prime numbers
from 1 to num.
A prime number is a number that is divisible by 1 and the number itself.
The input to the method primePrint consists of the input number num. Print all the
prime numbers from 1 to num, each separated by a comma. Do not return anything
from the method.
Please ensure that there are no other characters like spaces etc. are printed to the
screen. The output should only consist of comma-separated numbers.
For example:
num: 11
Output: 2,3,5,7,11
Useful Commands:
a%b returns the remainder when a is divided by b.
printf() prints the content within the brackets to the screen.
17: Given a unique positive integer array of length len with elements ranging
from 0 to (len-1), write a program to interchange the element value and its
corresponding index values.
For example: If a[0]=3, a[1]=2, a[2]=0,a[3]=1
then output is: a[0]=2, a[1]=3, a[2]=1,a[3]=0
The input to the function swapArr shall consist of an array arr and its length len.
The function should return an array after replacing the elements with their index values.
Useful Commands:
malloc() is used to dynamically allocate memory in C. The statement –
int *arr_new = (int*)malloc(len*sizeof(int));
creates an integer array arr_new of length len
18: Given a string str, write a program to eliminate all the vowels from it.
The list of vowels in English alphabet is: {a,e,i,o,u,A,E,I,O,U}
The input to the function eliminateVowelString shall consist of a string
str(containing only English letters) and returns a pointer to a string which does
not contain vowels.
Example:
Input:"abcdefghijklmnopqrstuvwxyz"
Output:"bcdfghjklmnpqrstvwxyz"
Useful commands:
strlen() is used to calculate the length of the string. The statement –
int len = strlen(str);
returns the length of the string str.
19: Given an integer N, print N lines in the following manner -
If N=4
the pattern generated would be
1*2*3*4
9*10*11*12
13*14*15*16
5*6*7*8
The input to the function squarePatternPrint shall consist of an integer N(Assume
0≤N≤100)
Do not return anything from the function. Print the required pattern using printf().
Each line of the output shall consist of ‘numerals’ and ‘*’ only. There should not be
spaces.
Useful commands:
printf() prints the content within the brackets to the screen.
20: Your are given an initial value and the dimensions of an increment matrix.
An increment matrix is a matrix is a matrix whose elements are the
incremented values of the initial value.
For example – if the initial value s = 1 and dimesions are : m=3, n=3, then the
increment matrix would be-
123
456
789
Multiply the given increment matrix with its transpose and return the resulting matrix.
The input to the function transposemultimatrix shall consist of the initial value s and
the dimensions of the increment matrix m and n, and function returns a 2-dimensional
matrix pointer allocated dynamically for the multiplication matrix.
Example – if initial value s = 1 and dimesions are : m=3,n=3
Increment Matrix:
123
456
789
Transpose Matrix:
147
258
369
Multiplied Matrix:
14 32 50
32 77 122
50 122 194
21:
Example 1:
Input;
Array size: 5
[ 1, 2,3, 4, 5]
Enter the key : 2
Output:
57963
Example 2:
Input;
Array size: 5
[ 5, 6,3, 4, 1]
Enter the key : -3
Output:
8 10 12 14 13
If the key value is positive,then the next two values of the array should be added(key
value is 2) and printed.
If the key value is negative ,then the previous three values of the array should be
added(key value is 3 ) and printed.
22: Create int data type array divide it do first half ascending, 2nd half
descending order
23: Check balanced expression using stack
This program uses stack to check balanced expression.The expression is parsed
character by character and when opening bracket is found, it is inserted into stack.When
the equivalent closing bracket is found, the stack is emptied. If the stack is empty after
parsing the entire expression,then the expression is balanced expression.
Example
{[()]} – Balanced Expression
{] – Un balanced Expression.
24: Encrypt the data with the following equation
(( (secret code)^N)%10)^M)%1000000007
Input: secret code,N,M.
25: Given a positive integer ranging from 0 to 99999999,find the number of
occurrences of a given digit in that number.
The input to the function shall consist of two positive integers, say num1 and num2 such
that 0<=num1<=9 and 0<=num2<=99999999.
The function findDigitOccurrence should return an integer variable with value equal to
the count of occurrences of num1 in num2.
For example: if num1=2 and num2=123228,the function should return 3 i.e. the no of
occurrences of num1 in num2.

Potrebbero piacerti anche