Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.

Roll No…………….. Total No. of Pages:……

ST-II (SET-III)

1st SEMESTER 2022-23

22CS002- FUNDAMENTALS OF C PROGRAMMING

Time allowed: 90 Minutes Max. Marks: 40

General Instructions:

● Follow the instructions given in each section.


● Make sure that you attempt the questions in order.

SECTION-A (10*1 mark=10 marks)

(All questions are compulsory)

1. Select the correct for loop which has a range of similar indexes of ‘i’ used in for (i=0;i<n;i++)?

a) for(i=n-1; i>0; i--)


b) for(i=n; i>=0; i--)
c) for(i=n-1; i>-1; i--)
d) for(i=n; i>0; i--)

2. A function is declared in which of the following formats:

a. type_of_return name_of_function (argument type);

b. type_of_return name_of_function (argument type){}

c. type_of_return (argument type) name_of_function;

d. all of the above

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

4. Identify the error in the following C declarations?

int func(int);
double func(int);
int func(float);

a) A function with the same name cannot have different signatures


b) A function with the same name cannot have different return types
c) A function with same name cannot have different number of parameters

_______________________________________________________________________22CS002- 2022-23
DO NOT WRITE ANYTHING ON QUESTION PAPER EXCEPT ROLL NO.

d) All of the mentioned

5.Predict the output of the following code:

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

7. What will be the output?

void main()

char *p=”Hello world”;

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

10) What will be the output of the program?

#include<stdio.h>
int main()
{
static int a = 3;
printf(“%d”, a --);
return 0;
}
a) 0
b) 1
c) 2
d) 3

MCQ (5*2 mark=10 marks)

(All questions are compulsory)

Q11What will be the output of the following Ccode?

#include <stdio.h>

void find() {

int arr[] = {11, 21, 31, 41, 51};

int s = 0;

for(int i = 0; i < 5; i++) {

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

Q 12What will be the output of the following C code?

#include<stdio.h>

void replace(int[]);

int main()

int arr[4] = {10,20,30,40};

replace(arr); printf("%d %d", *arr, arr[2]);

void replace(int a[])

a[0] = 50;

a) 10 30

b)50 30

c) 10 20

d) 20 30

Q 13What will be the output of the following C code?

#include<stdio.h>

int main()

intarr[5] ={8,9,10,11,12};

arr[3]=16;

int i=0;

while(i<4)

printf("%d ", arr[i]);

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.

Q14What will be the output of the following C code?

#include<stdio.h>

void main() {

int m[] = {8,9,10,11,12}, *p;

p = m;

++*p;

printf("%d ", *p);

p += 2;

printf("%d ", *p);

a) 11 12

b)9 10

c) 8 9

d) 10 11

Q15 Predict the output of the following C code?

#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

SECTION-C(Coding Question) (2x5 marks=10marks)

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.

Test Case Input Output

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

space-separated values representing the highest and lowest marks respectively.

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 Case Input Output

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()

int n,i, a[100];

int big=0, small;

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;

Coding Question (1x10 marks=10 marks)

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:

Throw dice any number of times.

The number occurs on dice.

Constraints:

1<=n<=6

Output:

Count how many times a number is occurring.

Sample test Cases

_______________________________________________________________________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 a[100], freq[100];

int size, i, j, c;

scanf("%d", &size);

for(i=0; i<size; i++)

scanf("%d", &a[i]);

freq[i] = -1;

for(i=0; i<size; i++)

c = 1;

for(j=i+1; j<size; j++)

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.

for(i=0; i<size; i++)

if(freq[i] != 0)

printf("%d:%d\n", a[i], freq[i]);

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

You might also like