Professional Documents
Culture Documents
ST 2 SET 3
ST 2 SET 3
ST-II (SET-III)
General Instructions:
1. Select the correct for loop which has a range of similar indexes of ‘i’ used in for (i=0;i<n;i++)?
3. If the condition is false at the beginning, which of the following will still execute the loop content:
a) while
b) do while
c )for
d) if else
int func(int);
double func(int);
int func(float);
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
void main()
{
int sum=0,i;
i=-2;
while(i<5)
{
sum=sum+i;
i=i+1;
}
printf(“%d”,sum);
}
a) 7
b) 10
c) -7
d) -10
6.In the condition of a while loop,the variable that is used for iterations is called:
a)Inner variable
b) Condition variable
c) Static variable
d)Counter variable
void main()
int *q;
p++;
q = (int *)p;
q++;
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
printf(“\n %s\n%s",p,q);
a) ello world
Ello world
b) Error
c) ello world
world
d) ello world
llo world
8) In C language,a pointer variable to an integer can be created by which of the following declarations:
a) int +p;
b) int $p;
c) int p*;
d) int *p;
9) In the given snippet, the sum variable represents which storage class:
# include<stdio.h>
Int main()
int sum;
printf(“%d”, sum);
return 0;
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
a) Extern
b) Register
c) Static
d) Auto
#include<stdio.h>
int main()
{
static int a = 3;
printf(“%d”, a --);
return 0;
}
a) 0
b) 1
c) 2
d) 3
#include <stdio.h>
void find() {
int s = 0;
if(i % 2 == 0) {
s += *(arr + i);
else {
s -= *(arr + i);
printf("%d", s);
int main() {
find();
return 0;
a)11
b) 51
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
c) 31
d) Error
#include<stdio.h>
void replace(int[]);
int main()
a[0] = 50;
a) 10 30
b)50 30
c) 10 20
d) 20 30
#include<stdio.h>
int main()
intarr[5] ={8,9,10,11,12};
arr[3]=16;
int i=0;
while(i<4)
i++;
A. 8 9 10 11
B. 8 9 10
C.8 9 10 16
D. 9 10 11 12
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
#include<stdio.h>
void main() {
p = m;
++*p;
p += 2;
a) 11 12
b)9 10
c) 8 9
d) 10 11
#include<stdio.h>
voidmm(int i);
int main()
mm(8);
return 0;
void mm(int i)
printf("88");
a)88
b) Error
c) 8
d) 0
Q 16.Statement: Virat received the result of "n" students. His task is to find out the highest marks in the class along with the number of students who scored the highest marks. For example, if a class has
n=5 students and the marks of the students are 22, 33, 23, 33, and 33 respectively then the output of the work performed by Virat must be 33 and 3. highest marks are 33 and 3 students scored 33 marks.
Input format
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
22 33 23 33 33
Output format
33 3
In the above example, the First line of the input is representing the total number of students i.e 5. The second line represents the marks obtained by these five students by five space-separated values. The
output display two space-separated values, the first value of output represents the highest marks obtained by the students and the second value of output represents the number of students who obtained the
highest marks.
TC1 5 33 3
22 33 23 33 33
TC2 6 66 1
55 66 44 33 12 22
TC3 3 77 3
77 77 77
TC4 6 76 2
55 76 44 76 12 22
TC5 7 78 1
55 66 44 33 12 22 78
Solution:
#include<stdio.h>
int main()
int a[100],n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
scanf("%d",&a[i]);
int big=0;
for (i=0;i<n;i++)
if(a[i]>big)
big=a[i];
int count=0;
for (i=0;i<n;i++)
if(a[i]==big)
count=count+1;
printf("%d %d",big,count);
return 0;
Q 17. A faculty needs to find out the highest and the lowest marks from the marks obtained by "n" students. Write a program that will take input as two lines. The first line of input shows
the total number of students in the class as "n". The second line will consider "n" space-separated values as the marks obtained by each student. The program will display output as two
Input:
22 33 11 44
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Output:
44 11
The first line of input shows the total number of students as 4. The second line of input shows 4 values as 22,33,11,44. The output shows two space-separated values 44 as the highest among the
different inputs entered and 11 as the lowest among the input values.
Test Cases:
Test_1 4 55 11
22 33 11 55
Test_2 5 22 10
10 12 13 14 22
Test_3 6 99 11
11 22 44 88 99 66
Test_4 3 44 1
1 44 5
Test_5 7 98 21
21 22 44 88 98 66
solution17:
#include<stdio.h>
int main()
scanf("%d",&n);
for (i=0;i<n;i++)
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
scanf("%d",&a[i]);
small=a[0];
for (i=0;i<n;i++)
if(big<a[i])
big=a[i];
if(small>a[i])
small=a[i];
printf("%d %d",big,small);
return 0;
Q 18.Rina is playing a game in which she is throwing a dice any no. of times. A dice contain a number from 1 to 6. After that, she is counting which number is occurring and how many times.There should
be no space before or after a colon(:) in the output.
Input:
Constraints:
1<=n<=6
Output:
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
Input Output
STC1 5 1:2
16361 6:2
3:1
STC2 5 4:2
45654 5:2
6:1
Solution:
#include <stdio.h>
int main()
int size, i, j, c;
scanf("%d", &size);
scanf("%d", &a[i]);
freq[i] = -1;
c = 1;
if(a[i]==a[j])
c++;
freq[j] = 0;
if(freq[i] != 0)
freq[i] = c;
_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.
if(freq[i] != 0)
return 0;
Test Cases
Input Output
TC1 6 1:2
121353 2:1
3:2
5:1
TC2 5 5:4
53555 3:1
TC3 7 2:3
2323211 3:2
1:2
TC4 6 6:2
656525 5:3
2:1
TC5 5 5:5
5555
_______________________________________________________________________22CS002- 2022-23