answer key
answer key
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);
#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>
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;
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]+b[i][j];
}
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;
}
#include <stdio.h>
int main()
int n;
scanf("%d", &n);
printf("Factorial of %d = %ld", n,
multiplyNumbers(n));
return 0;
}
if (n >= 1)
return n*multiplyNumbers(n-1);
else
return 1;