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

LabQues Final

Uploaded by

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

LabQues Final

Uploaded by

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

Indian Institute of Information Technology Sri City, Chittoor

(An Institute of National Importance under An Act of Parliament)

Name: Computer Programming Lab Examination Total: 20 Marks


Date and Time of the Exam: March 30, 2022 Duration: 90 Mins

Instructions: Code: cplabex


1) Read all questions carefully and answer both questions in the same c file.
2) Create a .c file with the following file name (Use hyphen and not underscore):
ABCD-YYYY-cplabex-AYCOY.c
Where

ity
ABCD represents the last 4 digits of your roll number(that may have preceding zeros)
YYYY represents the year of admission (2021 if you are admitted in last year)
cplabex is the Lab Exam code

iC
AYCOY - this can be any 5 English Alphabets in CAPITAL letters - Do not choose any
numbers or special symbols (this is your secret key and do not share with others).
3) Strictly follow the file naming convention and do not use scanf() anywhere. Improper
file naming convention will attract up to 20% penalty. So be aware of naming the C file.

Sr
4) You must answer both solutions in one .c file. It should have only one main function.
5) For other submission Instructions, please follow the announcements during the exam
------------------------------
1. [Marks = 8 (=3+5)] Assume (Initialize) the following 10 x 10 matrix:
IIT
7 2 5 2 8 2 3 4 2 5

11 18 3 10 23 1 13 31 50 2
-I

8 5 6 3 9 11 5 9 2 1

9 20 23 7 5 11 2 83 18 3
b

49 82 13 13 4 3 13 3 5 4
La

3 37 4 18 47 7 5 43 23 2

5 6 16 1 11 17 39 6 7 3

16 38 5 11 2 67 11 2 3 1
P

7 11 2 2 71 1 4 59 10 29
C

6 6 5 17 3 5 4 3 2 4

In the above matrix, consider all 3 x 3 matrices that have the following pattern of
values (two such patterns are highlighted in the above matrix with thick border):

7 2 5

11 18 3

8 5 6
Here the centered element (whose value is 18) is surrounded by 4 values at the
top, right, bottom and left (clockwise) as described below:
Top: The value is 2 in the above case
Right: The value is 3 in the above case
Bottom = The value is 5 in the above case
Left = The value is 11 in the above case
Center = This must be an even number - 18 in this case
Here Top, Right, Bottom and Left values must be prime numbers.

Now write different functions to do the following tasks:

ity
a) Write a function to check whether k is an even number / a prime
number or not? It may return 1, if the given number is an even number
/ a prime number and 0, otherwise

iC
int isEven(int k);
int isPrime(int k);
b) Write the following function to Identify all 3x3 matrices that satisfy the
above pattern and print all such 3 x 3 matrices:

Sr
int findandprint(int *arr, int m, int n);
This function returns the sum of top, right, bottom and left values (The above
two functions can be used in this function. You may write additional functions
as necessary)
IIT
2. [Marks = 12 (= 2 + 2 + 4 + 2 + 2)] Use dynamic memory allocation with pointers and
arrays (Do not use linked list )
-I

a) Define a structure namely POINT with two members: x and y (of type float)

b) Define a structure namely SQURECT using typedef with the following


members - P1, P2, P3, P4 - 4 members of type POINT, and area - of type
b

float. SQURECT structure represents either a square or a rectangle. So you


need to generate 4 points of type POINT in such a way that these 4 points
La

form either a square or a rectangle.

c) Write functions for the following tasks (Function names (case sensitive) are
given - Do not change these names):
i) Write a function to create n structures (using dynamic memory
P

allocation) by randomly generating four points P1, P2, P3, and P4 within
the grid [8.0, 8.0] and [20.0, 20.0] and length of the line connecting P1 and
C

P2 and the line connecting P2 and P3 should not exceed the boundary
of the above grid. Use srand() function with time / getpid() to initialize the
random number generator. Here n is the first command-line argument.
SQURECT *generateData(int n);

ii) Write a function to populate & print the area of all n SQURECT structures
void findArea(SQURECT *sr, int n);

iii) Write a recursive function to print 4 points and the area of each of n
SQURECT structures
void printValues(SQURECT *sr, int n);

You might also like