Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Dokuz Eylül University

Engineering Faculty
Department of Electrical and Electronics Engineering

EED1005 Introduction to Programming


Laboratory Exam - Makeup
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 10, 2022

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) The number 3797 has an interesting property. Being prime itself, it is possible
to continuously remove digits from left to right, and remain prime at each stage: 3797, 797,
97, and 7. Similarly, we can work from right to left: 3797, 379, 37, and 3. Note: 2, 3, 5, and
7 are not considered to be truncatable primes.
Write a C program that finds the first eleven primes that are both truncatable from left to
right and right to left. 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 number is a prime number
*
* @param number: The number to be checked
* @return int: Nonzero integer if number is prime
*/
int isPrime(int number);

/**
* @brief: Returns truncated number from right
*
* @param number: The number to be truncated.
* @return int: The truncated number.
*/
int truncateFromRight(int number);

/**
* @brief Trancates the number from left.
*
* @param number The number to be truncated.
* @return int The truncated number.
*/
int truncateFromLeft(int number);

1
The program must output as shown below.

The first 11 truncatable primes are:


1 => 23
2 => 37
3 => 53
4 => 73
5 => 113
6 => 131
7 => 137
8 => 173
9 => 179
10 => 197
11 => 311

3. (25 Points) Write a C program that takes an integer number from the user. The program
then constructs an array filled with the digits of the number. The program then prints the
digits of the number separated by one white space character. Note The user can enter an
integer with any number of digits.
In your program, implement the following functions given below.
/**
* @brief Finds the number of digits of `number`
*
* @param number The number whose number of digits is to be found
* @return int
*/
int numOfDigits(int number);

/**
* @brief Fill the `digits` array with the digits of `number`
*
* @param number The number whose digits is to be found
* @param digits The digits array to be filled
* @param size The size of the digits array.
*/
void fillDigits(int number, int digits[], int size);

/**
* @brief Prints the array in the backward direction.
*
* @param array The array to be printed.
* @param size The size of the array.
*/
void printArrayBackward(int array[], int size);

2
Three example executions of the program are given below.

Enter a number: 34567


3 4 5 6 7

Enter a number: 45
4 5

Enter a number: 7895467


7 8 9 5 4 6 7

4. (25 Points) Write a C program that computes cumulative sum of the numbers entered by
the user. The user enters -1 if he wants to exit the program. When taking number from the
user is completed, the program prints how many numbers are entered by the user and their
cumulative sum on the console. An example output execution of the program is given below.

Cumulative sum = 0.00. Enter a number(-1 to exit): 3


Cumulative sum = 3.00. Enter a number(-1 to exit): 4
Cumulative sum = 7.00. Enter a number(-1 to exit): 5
Cumulative sum = 12.00. Enter a number(-1 to exit): 6
Cumulative sum = 18.00. Enter a number(-1 to exit): 7
Cumulative sum = 25.00. Enter a number(-1 to exit): 2
Cumulative sum = 27.00. Enter a number(-1 to exit): 3
Cumulative sum = 30.00. Enter a number(-1 to exit): 4
Cumulative sum = 34.00. Enter a number(-1 to exit): 6
Cumulative sum = 40.00. Enter a number(-1 to exit): -1
Your entered 9 numbers. Cumulative sum is 40.00

You might also like