CP Sessional 2CS101 January 2021

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2CS101 Computer Programming

Nirma University
Institute of Technology
Sessional Examination, January 2021
B. Tech in CSE/EC/IC, Semester I
2CS101: Computer Programming

Roll/ Supervisor’s initial


Exam No with date

Time: 1 Hour 15 Minutes Max Marks: 40


___________________________________________________________________________________
Instructions:
i) Attempt all questions.
ii) Figures to the right indicate full marks.
iii) Assume necessary data wherever required.

Q.1 Do as directed: [10]


(i) Analyze the usage of linker. Is linker a system software or an 2
application software?
(ii) The syntax of "for" loop consists of following three parts: 2
1) Initialization 2) Condition 3) Increment/Decrement written as:
for (initialization; condition; increment/decrement)

Can we leave Increment/Decrement part blank and still perform


Increment/Decrement along with the condition checking part of
the for loop? [YES/NO]. Justify your answer by illustrating the
syntax of "for" loop for achieving above mentioned functionality.
(iii) Differentiate between break and continue statement. 2
(iv) Which of the following expressions are true? Justify your answer. 2
1) !(5 + 5 >=10)
2) 5 + 5 == 10 || 1 + 3 == 5
3) 5 >10 || 10 < 20 && 3 < 5
4) 10! =15 && !(10<20) ||15>30
(v) Perform the following conversion: 2
(93419.567)10 = ( ? )16

Q.2 Trace the code snippet given and show the output and tracing. In [10]
case of error, mention the error and justify it. Assume header files
are included.
(i) main( ) 2
{
int n;
for(n = 7; n!=0; n--)
printf("n = %d", n--);
}

Page 1 of 3
2CS101 Computer Programming

(ii) main( ) 2
{
enum Car {tata,audi=2,fiat,honda};
enum Car c;
c = audi;
switch(c) {
case tata:
printf("You choose tata!");
break;
case audi:
printf("You choose audi!");
break;
case 4:
printf("You choose fiat!");
break;
case honda:
printf("You choose honda!");
break;
default:
printf("I don't know your car.");
break;
}
}
(iii) main( ) 2
{
int a = 0;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;
case 1:
a = a - 1;
}
printf("%d \n ", a);
}
(iv) main( ) 2
{
char str[]="Hello";
str[strlen(str)+1]='#';
printf("str= %s\n",str);
}
(v) main( ) 2
{
int a, b, c;
Page 2 of 3
2CS101 Computer Programming
int arr[5] = {1, 2, 3, 25, 7};
a = ++arr[1];
b = arr[1]++;
c = arr[a++];
printf("%d--%d--%d", a, b, c);
}

Q.3 Draw flowchart to find whether a number is strong number or not. [6]
[Strong numbers are the numbers whose sum of factorial of
individual digits is equal to the original number. For example, 145
is a strong number as 1! + 4! + 5! = 1 + 24 + 120 = 145]

Q.4 Write a program to swap even positioned characters with odd [6]
positioned characters in a given string. Do not use any string
inbuilt function.

Q.5 Write a C program using a two-dimensional array to read, [8]


compute and print the following information from the table of data
mentioned below:

Item 1 Item 2 Item 3 Item 4


Salesman 1 Cost Cost Cost Cost
Salesman 2 Cost Cost Cost Cost
Salesman 3 Cost Cost Cost Cost

(a) Total value of sales by each salesman.


(b) Total value of each item sold.
(c) Grand total of sales of all items by all salesman.

*******************************

Page 3 of 3

You might also like