Professional Documents
Culture Documents
CP Sessional 2CS101 January 2021
CP Sessional 2CS101 January 2021
CP Sessional 2CS101 January 2021
Nirma University
Institute of Technology
Sessional Examination, January 2021
B. Tech in CSE/EC/IC, Semester I
2CS101: Computer Programming
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.
*******************************
Page 3 of 3