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><V1>

for example: CW15_Jane_Doe_123456MVEB21_T1_V1.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 1

 

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 vectors B, C and D.

·         Then in B put values in the range [0…9] from vector A,

in C values in the range [10…99] and in D [100…].

·         Display initial vector A, then vectors B, C and D.

 

Program output:

 

 

 

 

 

 

Task 2: Functions (2 points)

 

In main() are declared vectors A and B of size 5 with following integer values:

 

int A[5] = {5, 6, 7, 3, 9};

int B[5] = {1, 3, 4, 8, 6};//{1, 2, 4, 8, 0}

 

Pass vectors A and B to function findSmallestInBoth(),

·         which displays values of vectors A and B

·         then finds the smallest value that is located in both vectors and returns the found value; if there is no such value that is located in both A and B, then returns -1.

 

In main() if findSmallestInBoth() returns -1 then display message

“There is no such number that is located in both vectors A and B”,

otherwise display the obtained value and call function displaySum() which

·         sums up numbers in vector A that are not equal to the value found in function findSmallestInBoth()

·         and displays found sum

 

Program output:

 


 

 

 

 

Task 3: Pointers (2 points)

 

In main() ask the user to enter 3 integer numbers.

Then pass addresses of given numbers to function putEvenToZeroOddToOne(),

·         which displays entered numbers

·         then, if number is even it becomes 0, if odd it becomes 1.

 

In main() display modified numbers and then sum up them.

Then define if given sum even or odd.

Display corresponding message “The sum of entered numbers is even” or “The sum of entered numbers is odd”.    

 

 

Program output: