0% found this document useful (0 votes)
9 views6 pages

CT-II Set - B Answer Key

This document is a question paper for Cycle Test II for the B. Tech / CSE program at SRM Institute of Science and Technology, covering programming concepts in C. It includes questions on various topics such as control structures, arrays, string handling, and functions, along with coding examples and explanations. The paper is divided into two parts, with Part A requiring answers to 5 questions and Part B requiring answers to all questions.

Uploaded by

td4153
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

CT-II Set - B Answer Key

This document is a question paper for Cycle Test II for the B. Tech / CSE program at SRM Institute of Science and Technology, covering programming concepts in C. It includes questions on various topics such as control structures, arrays, string handling, and functions, along with coding examples and explanations. The paper is divided into two parts, with Part A requiring answers to 5 questions and Part B requiring answers to all questions.

Uploaded by

td4153
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Register No

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;
}

When the break statement is encountered inside a loop, the


loop is immediately terminated, and program control
resumes at the next statement following the loop. The break
statement can be used with all three of C's loops. One good
use of continue is to restart a statement sequence when an
error occurs
Illustrate the concept of nested for loop with suitable CLO-2 Analyze
Example?
#include <stdio.h>

int main () {

/* local variable definition */


int i, j;
3 4
for(i = 2; i<100; i++) {

for(j = 2; j <= (i/j); j++)


if(!(i%j)) break; // if factor found, not prime
if(j > (i/j)) printf("%d is prime\n", i);
}

return 0;
}
State the syntax of 2D array. Identify and Explain the CLO-3 Knowledge
subscript of 2D array

4 An array of arrays is known as 2D array. The two 4


dimensional (2D) array in C programming is also known as
matrix. A matrix can be represented as a table of rows and
columns.
Define one dimensional array and explain with example CLO-3 Knowledge

A one-dimensional array (or single dimension array) is a


5 type of linear array. Accessing its elements involves 4
a single subscript which can either represent a row or
column index. ... In the given example the array can contain
10 elements of any value available to the int type.
Demonstrate following string handling functions with code CLO-3 Apply
snippet (i) strlen() (ii) strcat()

6 4

strlen() – return the length of the string


7 Explain about Contiguous Memory Location in array CLO-4 Analyze 4
When Big Block of memory is reserved or allocated then that
memory block is called as Contiguous Memory Block.
Alternate meaning of Contiguous Memory is continuous
memory.
Suppose inside memory we have reserved 1000-1200 memory
addresses for special purposes then we can say that these 200
blocks are going to reserve contiguous memory.
Contiguous Memory Allocation
Two registers are used while implementing the contiguous
memory scheme. These registers are base register and limit
register.
PART – B
ANSWER ALL THE QUESTIONS (15*2 = 30)
Course Bloom’s
S. No S. No Question Outcom Taxono Marks
e my
8 Compare if else and switch case statements with example CLO-2 Evaluate

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

Need for User Defined Functions

It provides modularity to your program's structure.

It makes your code reusable. You just have to call the


function by its name to use it, wherever required.

In case of large programs with thousands of code lines,


debugging and editing becomes easier if you use
9 b functions. 15

It makes the program more readable and easy to


understand.

Function Prototypes

(a) Function with no Arguments and No Return values

b) Function with No Arguments and Return values

(c) Function with Arguments and No Return values

(d) Function with Arguments and Return values

You might also like