0% found this document useful (0 votes)
39 views4 pages

Lab Exam

Uploaded by

Trismegistus
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)
39 views4 pages

Lab Exam

Uploaded by

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

Dokuz Eylül University

Engineering Faculty
Department of Electrical and Electronics Engineering

EED1005 Introduction to Programming


Laboratory Exam
Instructions:

1. This exam contains 3 pages, excluding this page.

2. You have 4 questions (25 points each) and 120 minutes to complete the exam.

3. You have to take this exam on your own. If any form of cheating is detected in your
solutions, then those solutions will not be evaluated, and you will get 0 points.

4. If a function prototype is specified in a question, you have to comply with the


prototype. Otherwise, your solutions will be down-graded.

5. You are free with your solutions unless a function prototype is specified.

6. Write your programs in separate source files with .c extensions for each of the questions.
After writing all your programs, prepare a PDF file that includes the source codes, com-
ments and screenshots of the outputs of all your programs. Then, upload a single zip file
including the PDF file and your source files on the course webpage. Name your file
following this format: name surname id.zip. Below is shown the view of the content of the
zip file to be uploaded.
name surname id.zip
report.pdf
source codes
question 1.c
question 2.c
question 3.c
question 4.c
7. The laboratory assistant will be online during the examination and will except questions
about the exam for the first 15 minutes.

January 13, 2021

2021 - 2022 Fall Semester


1. (25 Points) Write a C program to print the pattern shown below. Do not just write printf
functions. You have to you use loops (for or while loops).

*****
*******
*********
***********
*************
*************
*************
*************
*************
*************
*************
***********
*********
*******
*****

2. (25 Points) A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2 . For example, 32 + 42 = 9 + 16 = 25 = 52 . There exists exactly one Pythagorean
triplet for which a + b + c = 1000.
Write a C program that finds a, b, c. In your program, implement the following function
given below. The text after @brief: is the brief explanation of the function, @param is the
explanation of the input arguments of the function and @return is the explanation of the
returned value from the function.

/**
* @brief: Returns nonzero integer if a, b and c is a Pythagorean triplet
*
* @param a: The first number in the triplet
* @param b: The second number in the triplet
* @param c: The third number in the triplet
* @return int: Nonzero integer if a, b, c is a Pythagorean triplet.
*/
int isPythagoreanTriplet(int a, int b, int c);

In the main function, loop over the numbers i, j, k = 1, 2, . . . , 500 and check if the triplet
(i, j, k) is a Pythagorean triplet by calling isPythagoreanTriplet. If such a triplet is found,
print (i, j, k) on the console. A sample execution of the program is given below.

The Pythagorean triplet is (200, 375, 425)

1
3. (25 Points) Write a C program that initializes an array of size 5 × 5 with random integers
from the interval of [0, 99] and finds the maximum of the product of the elements of array.
In your program, implement the following functions given below.

/**
* @brief: Prints the array of size size-by-size.
*
* @param array: The array to be printed
* @param size: The size of the array
*/
void printArray(int array[SIZE][SIZE], int size);

/**
* @brief: Fills the array with random integers from the range of [0, 99].
*
* @param array: The array to be filled
* @param size: The size of the array.
*/
void fillArray(int array[SIZE][SIZE], int size);

/**
* @brief: Returns the maximum of the product of elements of array
*
* @param array: The array to be searched
* @param size: The size of the array
* @return int: The maximum of the product of elements of array.
*/
int findMaxProduct(int array[SIZE][SIZE], int size);

In the main function, create an array of size 5 × 5, fill the array by calling fillArray and
print the array by calling printArray function. Then, find the maximum of the product of
the elements of array by calling findMaxProduct function. An example execution of the
program is given below.

The content of the array:


83 86 77 15 93
35 86 92 49 21
62 27 90 59 63
26 40 26 72 36
11 68 67 29 82

Maximum of the product of elements is 8556

2
4. (25 Points) Factorial digit sum is the sum of digits of n! = n × (n − 1) × . . . × 3 × 2 × 1. For
example, 10! = 10 × 9 × . . . × 3 × 2 × 1 = 3628800 and the sum of the digits in the number
10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Write a C program that finds the sum of the digits in the number 20!. In your program,
implement the following functions given below.

/**
* @brief: Returns n!.
*
* @param n: The number whose factorial will be computed.
* @return unsigned long int: The value of the n!
*/
unsigned long int factorial(int n);

/**
* @brief: Returns the sum of digits of `number`
*
* @param number: The number whose digits will be summed.
* @return int: The sum of digits of number.
*/
int sumOfDigits(unsigned long int number);

In your main function, compute 20! by calling factorial and find the sum of digits of 20!
by calling sumOfDigits. Print the value of 20! and the sum of digits of 20! on the console.
When executed the program must output as shown below.

20! = 2432902008176640000
The sum of digits of 20! is 54

You might also like