Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSD101 Introduction to computing and programming-mid semester-question paper-2022, Exams of Computer Science

Mid semester examination question paper based on the language C.

Typology: Exams

2021/2022

Available from 10/13/2022

mansi-kulshreshtha
mansi-kulshreshtha 🇮🇳

4 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. The code fragment below finds the maximum and minimum elements in
the integer array arr and stores them in mval[0] (max value) and mval[1]
(min value). Fill in the parts shown by ?m?, m=1 to 8 so that the program
works correctly. n is the size of the array.
Ans:
?1?: int, int
?2?: int, int
?3?: k<n
?4?: max(mval[0], arr[k]);
?5?: min(mval[1], arr[k]);
?6?: k+1
?7?: (a>b)?a:b; or equivalent
pf3
pf4
pf5

Partial preview of the text

Download CSD101 Introduction to computing and programming-mid semester-question paper-2022 and more Exams Computer Science in PDF only on Docsity!

1. The code fragment below finds the maximum and minimum elements in

the integer array arr and stores them in mval[0] (max value) and mval[1]

(min value). Fill in the parts shown by ?m?, m=1 to 8 so that the program

works correctly. n is the size of the array.

Ans:

?1?: int, int

?2?: int, int

?3?: k<n

?4?: max(mval[0], arr[k]);

?5?: min(mval[1], arr[k]);

?6?: k+

?7?: (a>b)?a:b; or equivalent

?8?: (a<b)?a:b); or equivalent

8*1=8 marks

2. Consider the following program:

void main()

char a, b;

int c;

scanf(“%c%c%d”, &a, &b, &c);

if (a == ‘a’)

if (b == ‘a’)

printf(“%c\n”, b);

else

printf(“%c\n”, a);

4. Write conditional operators to evaluate the following function

y = 2.4x + 3, for x <= 2

y = 3x – 5, for x > 2

Ans: y = (x<=2)? (2.4x + 3) : (3x - 5) or equivalent

2 marks. No partial marks.

  1. Write a function in C named stringcomp, to perform the task of the strcmp function. Your function will accept two strings to compare, and return an integer measuring the difference. Ans: int stringcomp(char str1[], char str2[]) { int ret = 0; for (int i = 0; 1; i++) { if (str1[i] != str2[i]) { return str1[i]-str2[i]; } if (str1[i] == '\0' || str2[i] == '\0') return 0; } } Students may write the same code in different ways. 5 marks
  2. See the following code segment: char arr[3][4]={‘a’,’z’,’b’,’y’,’c’,’x’,’d’,’w’,’e’,’v’,’f’,’u’}; printf(“%d\n”, arr[1][2]); What will be printed? Ans: 100 2 marks, no partial marks.
  3. What will be the output of the following code segment: char s[10]=”Hello”; int i;

for(i=0;s[i]!=’\0’;i++); printf(“%d\n”, i); Ans: 5 2 marks Only one value will be printed. Marks will be given only for this answer. For any other answer (even containing 5) will get 0 marks.

  1. Write an appropriate macro such that, it will accept the marks and return “pass” if the marks is more than 60; and “fail” otherwise. Ans: #define grade(marks)(marks>60)?"pass":"fail" 2 marks No partial marks

See the code below: #include<stdio.h> int hello(int n) { return n++; } void main() { int n=5; n=hello(n++); printf("%d"\n, n); } What will be printed? Use the two '++' operators in suitable ways so that the output is 7. Answer: 5 Write ++n in place of n++ for both the cases. 2 marks: 1 mark for each correct answer