Write a C program that will read a line of text and delete all occurrences of the
article ‘an’ from entered text.
Also count the number of ‘an’ removed from the entered
text. (15M)
Input text should be all lowercase characters and remove only the two letter word ‘an’.
Example :
Input :
“an owl an elephant an umbrella an animal an apartment all are examples of an
article”
Output:
owl elephant umbrella animal apartment all are examples of article
Count of an removed from entered text = 6
You are given input number n, then you will be given ‘n + 3’ numbers as input that
you have to store in an array ,each number given to you as input lies between [1,n] ,
every number in those ‘n+3’ numbers given to you as an input comes only once except
one number that comes 4 times, you have to (15M)
(i) Print that repeated number
(ii) Print all the numbers that come before the first occurrence of that repeated number
in the array
Note: You are allowed to use only one array in your whole code
Note : n should be less than 50
Input: n = 5
Arr = 1 2 5 4 3 4 4 4
Ans : Repeated Number : 4
Numbers in the array before the first occurrence of repeated number
1 2 5
Write a C program that will take n numbers through the keyboard by the user and
delete the first k numbers from the beginning of the array. Then append m numbers at
the end of the array. Print the arrays after every operation. (20M)
Example :
n=5, array- 5,6,7,2,3
k=2, after deletion the array - 7,2,3
m=3, after insertion the array - 7,2,3,4,1,6
Take an integer array P of length >=2, where all the elements are distinct. In the
array P, a group is defined as (P[m], P[n]) where m and n are array indices and they are
distinct. (25M)
I. Find all such groups from the array P. Print the groups along with the maximum
among the elements in each group. Also, store the maximum among the
elements of each group in an array L.
II. In the array P, we have the following property for some of the groups: P[m]>P[n]
when m
Sample Input: P is {8,7,12,15,4}
Sample Output:
(I) Possible groups = (8,7), (8,12), (8,15), (8,4), (7,12), (7,15), (7,4),
(12,15), (12,4), (15,4)
Maximum in each group = 8, 12, 15, 8, 12, 15, 7, 15, 12, 15
(II) The groups satisfying the property (P[m] > P[n] & m < n) are:
Group:(8,7)
Group:(8,4)
Group:(7,4)
Group:(12,4)
Group:(15,4)
Write a C program to accept a key string and some test string from the user through
the keyboard. The program should validate the test string, and return the message that
whether the key string is present in the test string or not. (25M)
Note: If a key string is present in the test string means the frequency of characters of
key string should either match or below the frequency of characters of the test string
Example :
Key string = "ab"
Test string = “ac”
Key string is not present in the Test string.
Key string = "ab"
Test string = “acb”
Key string is present in the Test string.
Key string = "abbbcdd"
Test string = “abcdbdbefdba”
Key string is present in the Test string.
Key string = "abbbcdd"
Test string = “abbcbdasc”
Key string is not present in the Test string.
[NOTE: The solution include both versions of comparison (case sensitive and
insensitive) under different comment, if you want to run the code with a particular
constraint, please remove the others part before compiling]
User supplies two strings X and Y of at most 20 characters from
English alphabet (a to z and A to Z) .
Store them in two 1D arrays.
Find and print their longest common sub string, ignoring the difference between uppercase
and lowercase. May use string related functions.
Example
Enter X: ProGraMming
Enter Y: grammar
Answer :gramm
Write a C-program to read marks in the Programming and Data
Structure Laboratory (out of 100) for N (to be read before) students.
Consider the interval of marks 0-5, 6-10, 11-15, and so on.
Note that
the first interval contains 6 numbers, and other intervals are of 5
numbers. Find the interval of marks having maximum number of
students in the class and compute the difference between its center
point from the mean of the distribution of marks.
Provide results for the following inputs:
1. N=20
45, 56, 60, 15, 80, 90, 12, 85, 35, 58,
63, 73, 52, 78, 47, 23, 14, 58, 18, 96
2. N=30
54, 65, 6, 51, 8, 9, 21, 58, 53, 85,
36, 37, 25, 87, 19, 93, 44, 85, 17, 69,
40, 0, 3, 33, 16, 63, 95, 69, 74, 38
Write a C-program to read a number N and then to read weights
(in Kg) of N students in an array.
Compute the mean, median and
standard deviation of their weights. Provide results for the following
inputs:
1. N=20
45, 56, 60, 65, 80, 90, 102, 85, 65, 54,
63, 73, 52, 78, 47, 43, 44, 58, 88, 96
2. N=30
54, 65, 62, 51, 84, 49, 41, 58, 53, 85,
46, 47, 55, 87, 99, 93, 44, 85, 77, 69,
40, 70, 53, 63, 76, 63, 95, 69, 74, 58
Write a C-program, which reads five English words in the
following order, an article (A/An/The), a noun, a verb (in simple
present or past tense), an article, and a noun. For any of these words,
if you provide a digit as a string, it will consider the word as an empty
string. The program forms an English sentence in another string by
taking care of blank spaces in between and appending the punctuation
symbol ‘full stop’ (.) at the end.
While converting, it would take care
of converting any upper case alphabet to a lower case alphabet if it is
not the first word of the sentence.
Similarly, it would convert a lower
case alphabet of the first alphabet of the first word in the sentence to
an upper case alphabet. Finally, it prints the sentence.
For example:
(i) Input: “the”, “Girl”, “reads”, “a”, “Book”.
Output: “The girl reads a book.”
(ii) Input: “5”, “they”, “Went”, “2”, “Home”.
Output: “They went home.”
Provide results for the following inputs:
1. “A”, “man”, “asks”, “The”, “Person”.
2. “0”, “Rahim”, “throws”, “the”, “football”.
3. “the”, “dog”, “chases”, “the”, “cat”
Write a C program which first reads and integer n (< 100).
Then read n integers and store them in a one dimensional array.
The program should then print the value of the largest number in the array.
Consider an array A of integers. In this assignment, you
will have find and print all non-duplicate elements in A, in
the same order as they appear in A
Ex:
If A has 12, 3, 4, 11,12, 4, 13, 12, you should print 12, 3,
4, 11, 13
If A has 3, 3, 3, 6, 1, 3, 3, 6, you should print 3, 6, 1
Write a C program that
Read in an integer n (assume n < 20)
Read in n integers in an array A
Print the integers read
Print the non-duplicate integers in A as above
Hint:
Use another array B, initially containing 0 elements
For each element in A (one loop), check if the element
is already in B (compare with each element of B in
another loop nested inside the first loop)
If yes, do nothing
If no, add to B after the last element (initially no
element in B, so add to index 0 for the first one) and
update the number of elements in B
At the end, print the elements in B
A string is called a palindrome if it reads the same
backward or forward
Example, “madam”, “radar”, “abcddcba”,….
Write a C program that will do the following in the order
given:
Reads in a string in a character array S using %s format
in scanf
Type the string with no space and end it with pressing
Enter
Assume that the size of the string (including the ‘\0’ at the
end will not be more than 50 characters)
Remember that for reading with %s, you give only the
name of the character array in which you want to read,
without any & in front Computes and prints the length of the string
Length = number of characters in the string not counting the ‘\0’at
the end
Write a for loop to check the characters in the array S one by one
till you get the character ‘\0’
Reads in an integer p
Checks if the string S has any palindrome of length p or not
If yes, print the palindrome part of the string only
If there are more than one such palindrome, print any one
Once you find such a palindrome, you should stop checking
and break out of the loop (use break statement)
If no, print a message
Do NOT use any other array or write any functions even if you know
it (50% penalty if any other array is used or any function is used)
Hint: Start from each character in S from the start (one loop) and
check if there is a palindrome of length p starting from it (another
loop)
Example:
If S = “abccba” and p = 6, prints “abccba” (as S is itself a
palindrome of length 6)
If S = “abccba” and p = 4, prints “bccb” (as “bccb” is a
palindrome of length 4 inside S)
If S = “abccba” and p = 2, prints “cc” (as “cc” is a palindrome
of length 2 inside S)
If S = “abccba” and p = 3, prints “No palindrome of length 3 in
S” (as there is no palindrome of length 3 inside S)
If S = “abbcddc” and p = 4, prints any one of “abbc” or “cddc”
(as both are palindromes of length 4 inside S). Which one
you hit first will depend on the way you write your program.
In all cases, once it finds a palindrome and prints it, it should
not check for palindromes any more (break from for loop)
Write a C program to reverse the elements of an 1-D array of type double.
Input the elements
of the array successively until ‘-1’ is pressed by the user.
The elements must be of type double.
You have to use a single array only.
Write a C program to take input a sentence as a character array and convert all vowels in the sentence to uppercase.
SolutionWrite a C program to take 10 non-repetitive integers in the range from 1 to 100 as input and
store it in an array ‘X’.
Find the maximum value ‘m’ in ‘X’ and create an empty array ‘Y’
with size ‘m’.
The array ‘Y’ is initialized with “0”. Now, take each integer “i” stored in X and
perform ‘Y[i]=1’.
Finally, traverse the whole array ‘Y’ from end to the beginning, and print the
indices of elements that contain ‘1’.
Observe the input and output and write your observation
in the source file as a comment.
Write a C Program to find out the value and position of the largest and the second largest
element in an array with size 20.
Thereafter, swap the position of the above two numbers
without using a third variable.
You are not allowed to sort the array as well.
Write a C program to take input a paragraph as a single character array and a given word into
another character array.
Hence count the number of times the word appears in the paragraph
and for each appearance of the word, change all the characters of that word to uppercase in the
paragraph. (For taking a sentence with blank spaces between words as input, you have to use
“%[ˆ\n]s” in ‘scanf’ function).
Example:
• Input:
– Paragraph: The sun is the nearest star to Earth. The sun gives us light and heat. It is
because of the sun that all life on Earth exists
– Word : sun
• Output:
– Paragraph: The SUN is the nearest star to Earth. The SUN gives us light and heat. It
is because of the SUN that all life on Earth exists
User supplies two lists A and B containing m and n integer elements respectively. Find the elements common to A and B, and print
them.
Example:
Input: m=5,n=7,A=[2 5 4 4 1] B =[3 4 4 4 1 2 2].
Output: Common elements: 2, 4, 1.
Write a program to separate odd and even integers in separate arrays.
Assume that the array can hold maximum 20 integers.
input: No. of elements in the array, the different integer values in the array
output: One array for odd integers and one array for even integers
Write a program that will insert a new value to an already existing sorted array such that the sorting is maintained. You can assume
1. Assume that the user provides the elements of the original array in already sorted order (ascending order)
2. Assume that the modified array can hold maximum 10 values
input: No. of elements in the array, the different values in the array in sorted order, the new value to be inserted
output: The original array, the modified array
[Applying any sorting algorithm is not allowed]
Write a program to find the frequency of the smallest value in the array.
input: No. of elements in the array, the different values in the array
output: The minimum value and the frequency of the minimum value
[Think: You can naively do it in two steps. First you can find the minimum value and then look for the number of times it has occured.
Can you think of a way by which this is done in a single step i.e., in one traversal of the array?]
Take as input two natural numbers m and n (both between 1 and 10), followed by m and n distinct integers, both sorted in ascending
order (user enters elements in sorted order). Store them into two integer arrays A and B of length 10 each. Merge them into 1 single
sorted array C of length 20. Print C.
Example:
Input: m=4,n=5,A=1 10 15 30, B=5 20 35 40 80.
Output: c = 1 5 10 15 20 30 35 40 80.
[Applying any sorting algorithm is not allowed]
A palindrome, in general, is a word, phrase, number, or other sequence of characters, which reads the same backward or forward.
Your task is to take as input a string, print its length, and check whether it is a palindrome.
No library function should be used excepting stdio.h.
Examples
Enter a string (of at most 100 characters): malayalam
Length of malayalam = 9
palindrome
Enter a string (of at most 100 characters): Malayalam
Length of Malayalam = 9
not a palindrome
Enter a string (of at most 100 characters): 16ab61
Length of 16ab61 = 6
not a palindrome
Enter a string (of at most 100 characters): 16aba61
Length of 16aba61 = 7
palindrome