Topic: C programming: classwork.

Content:  classwork (only in class)

 

Classwork assignment (only in class)

Gentle Reminder!

You can get points only if you send us your solutions of [only-in-class] classwork assignments:

You must submit your [only-in-class] solution before the end of a lesson! The solutions, sent after that, will not be graded.

 

You can use any arbitrary materials, if desired, but conversations with each other are prohibited.

If conversation (incl. communication by chats, e-mail etc.) occurs the participants will get “0” (ZERO) points for this assignment.

If you are a member of plagiarists’ team, your solution can be graded as “0” (ZERO).

 

Name your solution file and topic of an e-mail letter as follows:

CW<a consecutive number of a lesson>_<firstname>_<lastname>_<studentID>group<group number><T1><V2>

for example: CW15_Jane_Doe_123456MVEB21_T1_V2.c

 

You must send your solutions to both of us:           

Dr Marina Brik             marina.brik@ati.ttu.ee  

Dr Sergei Kostin      sergei.kostin@gmail.com

 

 

VARIANT 2

 

Task 1: Arrays (2 points)

 

Vector A of size 10 is given with following integer values:

 

int A[10] = {534, 11, 6, 175, 54, 1, 9, 32, 7, 13};

 

·         Create array B with two columns and put in the first column even numbers from vector A

and in the second column odd values from vector A.

·         Display initial vector A and array B row by row (if element does not have any value, then print empty space).

 

Program output:

 

 

 

 

Task 2: Functions (2 points)

 

In main() is declared vector X of size 5 with following integer values:

 

int X[5] = {1, 6, 7, 4, 9};

 

Pass vector X to function getClosestToMean(),

·         which finds the mean value (integer) for given numbers

·         then displays given numbers and the mean value

·         finally, the function finds a number from vector X that is closest to the mean value but also is greater than the mean value.

 

In main() display the obtained value from function getClosestToMean.

Then pass vector X and the closest to the mean value to function displaySmallerThan(),

·         which displays values from vector X that are less than the closest to the mean value.

 

Program output:

 

 

 

Task 3: Pointers (2 points)

 

In main() ask the user to enter 3 small letters.

NB! Add space between " and % to read a character correctly:   scanf(" %c", &a);

 

Then pass addresses of given letters to function makeLettersCapital(),

·         which displays entered letters

·         then, modifies given letters by subtracting from current value 32.

 

In main() display modified letters and check if first and second letters are neighbor letters in the alphabet or not.

Display message “A and D are NOT neighbor letters in the alphabet” or “A and B are neighbor letters in the alphabet”.

 

NB! The letters are neighbor if their integer value differ by 1 (Look at ASCII character encoding).   

 

For instance:

char c1 = 'a';//97

char c2 = 'b';//98

printf("%d", c2-c1); // displays 1

 

Program output: