CT-II Set - B Answer Key
CT-II Set - B Answer Key
Set - B
FACULTY OF ENGINEERING AND TECHNOLOGY
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CYCLE TEST – II / QUESTION PAPER
ACADEMIC YEAR 2018 -2019 / EVEN
Batch 1 / Set B-Answer Key
Program Offered: B. Tech / CSE Year / Semester: I / II
Max. Marks: 50 Duration: 1 Hour 40 Mins
Date of Exam: 25/03/2019
Course Code & Title: 18CSS101L – PROGRAMMING FOR PROBLEM SOLVING
PART –A
ANSWER ANY 5 QUESTIONS (4*5=20)
Course Bloom’s
S. No Question Marks
Outcome Taxonomy
Write a C program to input any alphabet and check whether CLO-2 Create
it is consonant or vowel using else-if construct
#include<stdio.h>
int main( )
{
char c;
int isLowercaseVowel, isUppercaseVowel;
printf("Enter an alphabet: ");
scanf("%c",&c);
1 4
isLowercaseVowel =(c =='a'|| c =='e'|| c =='i'|| c =='o'|| c =='u');
isUppercaseVowel =(c =='A'|| c =='E'|| c =='I'|| c =='O'|| c
=='U');
if(isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return0;
}
2 Explain Switch case Statement ? How break Statement is CLO-2 Understand 4
useful in C programming
switch(variable or expression)
{
case constant 1:
statements;
break;
….
case constant N;
statements;
break;
default:
statements;
}
int main () {
return 0;
}
State the syntax of 2D array. Identify and Explain the CLO-3 Knowledge
subscript of 2D array
6 4
a(i) 8
a(ii) write a program to count total number of even and odd element CLO-2 Create 7
in array
#include<stdio.h>
int main()
{
int Size, i, a[10];
int Even_Count = 0, Odd_Count = 0;
printf("\n Please Enter the Size of an Array : ");
scanf("%d", &Size);
printf("\nPlease Enter the Array Elements\n");
for(i = 0; i < Size; i++)
{
scanf("%d", &a[i]);
}
for(i = 0; i < Size; i ++)
{
if(a[i] % 2 == 0)
{
Even_Count++;
}
else
{
Odd_Count++;
}
}
printf("\n Total Number of Even Numbers in this Array =
%d ", Even_Count);
printf("\n Total Number of Odd Numbers in this Array =
%d ", Odd_Count);
return 0;
}
(Or)
Design a menu and write a C program to perform the
Factorial or Fibonacci of a given number based on the user
choice
#include<stdio.h>
int main( )
{
int square, i, n, fact = 1, t1 = 0, t2 = 1, nextTerm ,choice;
printf(“\n Enter Any Number: ”);
scanf(“%d”, &n);
printf(“ 1. Factorial \n”);
printf(“ 2. Fibonacci \n”);
printf(“ 4. Exit \n”);
printf(“ Enter your Choice”);
scanf(“%d”, &choice);
switch (choice)
{
case 1:
for(i=1;i<=n;i++)
{
b(i) CLO-3 Create 10
fact = fact * i;
}
printf(“The Factorial of a given number is %d\n”, fact);
break;
8 case 2:
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
break;
}
case 3:
exit(0);
default:
printf(“Invalid Choice. Please try again\n”);
}
return 0;
}
Differentiate between Entry controlled and Exit Controlled CLO-2 Analyze
Loop
b(ii) 5
9 a Illustrate functions using call by value and CLO-4 Analyze 15
call by reference method with suitable
examples.
Call by Value
Example: Swapping the values of the two
variables
#include <stdio.h>
void swap(int , int); //prototype of the
function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in
main a = %d, b = %d\n",a,b); // printing the
value of a and b in main
swap(a,b);
printf("After swapping values in main a =
%d, b = %d\n",a,b); // The value of actual
parameters do not change by changing the
formal parameters in call by value, a = 10, b
= 20
}
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function
a = %d, b = %d\n",a,b); // Formal
parameters, a = 20, b = 10
}
Call by Reference
#include <stdio.h>
void swap(int *, int *); //prototype of the
function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in
main a = %d, b = %d\n",a,b); // printing the
value of a and b in main
swap(&a,&b);
printf("After swapping values in main a =
%d, b = %d\n",a,b); // The values of actual
parameters do change in call by reference, a
= 10, b = 20
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function
a = %d, b = %d\n",*a,*b); // Formal
parameters, a = 20, b = 10
}
(Or)
Discuss the need for user defined functions? Explain CLO-4 Understand
with suitable example programs the four function
prototype
Function Prototypes