0% found this document useful (0 votes)
5 views

answer key

This document is a question paper for the Cycle Test II for the B.Tech in Computer Science and Engineering program at SRM Institute of Science and Technology. It includes questions on programming concepts, C programming exercises, and theoretical questions related to arrays, recursion, and control statements. The paper consists of two parts: Part A with 5 questions to answer and Part B with all questions to answer, totaling a maximum of 50 marks.

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)
5 views

answer key

This document is a question paper for the Cycle Test II for the B.Tech in Computer Science and Engineering program at SRM Institute of Science and Technology. It includes questions on programming concepts, C programming exercises, and theoretical questions related to arrays, recursion, and control statements. The paper consists of two parts: Part A with 5 questions to answer and Part B with all questions to answer, totaling a maximum of 50 marks.

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/ 7

Register No

Set - D
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 2 / Set D- 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
State the advantage and limitation of arrays

Advantages of Arrays
1. It is used to represent multiple data items of same type by
using only single name. 2. It can be used to implement other
data structures like linked lists, stacks, queues, trees, graphs
etc.
3. 2D arrays are used to represent matrices
Limitations of Arrays
1. We must know in advance that how many elements are to be
stored in array.
2. Arrayis static structure. It means that array is of fixed size.
1 CLO-2 Knowledge 4
The memory which is allocated to array can not be increased
or reduced.
3. Sincearray is of fixed size, if we allocate more memory than
requirement then the memory space will be wasted. And if we
allocate less memory than requirement, then it will create
problem.
4. The elements of array are stored in consecutive memory
locations. So insertions and deletions are very difficult and
time consuming.

Write a C program to Check whether a number is Even or Odd using CLO-2 Create
Conditional operator

#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
2 4
(number % 2 == 0) ? printf("%d is even.", number) : printf("%d is
odd.", number);
return 0;
}
Sample Output:
Enter an integer: 3
3 is odd.
Enter an integer: 4
4 is even
Print the pattern using looping concept in C. CLO-2 Apply
*****
****
***
**
*
#include <stdio.h>
int main()
{
inti, j, rows;
printf("Enter number of rows: ");
3 scanf("%d",&rows); 4
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("\n");
}
return 0;
}
Outline the various methods of obtaining input in a character array CLO-3 Knowledge

Syntax:
scanf(“Control String(%s)”,characterarray_name);
Read the String until null or newline i.e without white space
Example:
#include<stdio.h>
int main()
{
4 char arr[10];
4
scanf(“%s”,arr);
printf(“%s”,arr);
return 0;
}
Syntax:
Scanf(“Control string(%[^\n])”,characterarray_name);

String with white space


Define array. How to initialize an one dimensional and multi CLO-3 Understand
dimensional array?

An array is defined as finite ordered collection of homogenous data,


stored in contiguous memory locations.

Array is used to store a collection of data


5 4
Array is a collection of variables of the same type.

Single dimensional arrays are used to store list of values of same


datatype. In other words, single dimensional arrays are used to store a
row of values. In single dimensional array, data is stored in linear form.
Single dimensional arrays are also called as one-dimensional arrays,
Linear Arrays or simply 1-D Arrays.
6 Write a C program to find the sum marks of n students using arrays. CLO-3 Apply 4

#include <stdio.h>
int main(){
int marks[10],i,n,sum=0;
printf("Enter number of students: ");
scanf("%d",&n);
for(i=0;i<n;++i){
printf("Enter marks of student%d: ",i+1);
scanf("%d",&marks[i]);
sum+=marks[i];
}
printf("Sum= %d",sum);
return 0;
}
Write a program in C to find the square of any number using functions. CLO-4 Apply

#include <stdio.h>

double square(double num)


{
return (num * num);
}
int main()
{
7 int num; 4
double n;
printf("\n\n Function : find square of any number :\n");
printf("------------------------------------------------\n");

printf("Input any number for square : ");


scanf("%d", &num);
n = square(num);
printf("The square of %d is : %.2f\n", num, n);
return 0;
}
PART – B
ANSWER ALL THE QUESTIONS (15*2 = 30)
Course Bloom’s
S. No S. No Question Outco Taxono Marks
me my
8 a(i) Illustrate the post increment and pre decrement operator with CLO-2 Apply 5
suitable example in c

/* Expresssions using Post-Increment Operator*/


#include<stdio.h>
int main( )
{
int x,i;
i=10;
x=i++;
printf("x: %d",x);
printf("i: %d",i);
return 0;

/* Expresssions using Pre-Decrement Operator*/


#include<stdio.h>
int main( )
{
int x,i;
i=10;
x=--i;
printf("x: %d",x);
printf("i: %d",i);
return 0;
}
Define recursion function ? Write a C program to illustrate CLO-2 Knowledg
use of recursion function e

a(ii) 10

(Or)
Explain with suitable example the various control statements CLO-2 Evaluate
available available in C

8 b 15

9 a Apply any technique and write a C program to sort the CLO-3 Apply 15
given array in ascending or descending order
a[ ]={24 , 7 , 12 , 18 , 6 , 14}

(Or)
9 b(i) Assume there are two three dimensional matrices A and CLO-3 Apply 8
B. Perform addition of these two matrices and store in a
third matrix C.
#include <stdio.h>
int main(){
int r, c, a[100][100], b[100][100], sum[100][100], i,
j;

printf("Enter number of rows (between 1 and 100):


");
scanf("%d", &r);
printf("Enter number of columns (between 1 and
100): ");
scanf("%d", &c);

printf("\nEnter elements of 1st matrix:\n");

for(i=0; i<r; ++i)


for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}

printf("Enter elements of 2nd matrix:\n");


for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &b[i][j]);
}

// Adding Two matrices

for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]+b[i][j];
}

// Displaying the result


printf("\nSum of two matrix is: \n\n");

for(i=0;i<r;++i)
for(j=0;j<c;++j)
{

printf("%d ",sum[i][j]);

if(j==c-1)
{
printf("\n\n");
}
}

return 0;
}

b(ii) Write a C program to find the factorial of a given CLO-4 Create 7


number using recursion

#include <stdio.h>

long int multiplyNumbers(int n);

int main()

int n;

printf("Enter a positive integer: ");

scanf("%d", &n);

printf("Factorial of %d = %ld", n,
multiplyNumbers(n));

return 0;
}

long int multiplyNumbers(int n)

if (n >= 1)

return n*multiplyNumbers(n-1);

else

return 1;

You might also like