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

Computer Engineering Department TED University: CMPE 252 - C Programming, Spring 2021 Lab 2

This document provides instructions for Lab 2 of the CMPE 252 - C Programming course. It outlines 3 parts that involve implementing functions to: 1) Circularly shift an array from left to right. 2) Compare two arrays and return values based on their equality or the first differing element. 3) Circularly shift an array until it is in its maximum configuration by comparing shifts. Skeleton code files are provided for each part, and the tasks involve filling in the missing function definitions while keeping the main functions intact. Sample runs are included to demonstrate expected behavior.

Uploaded by

mert
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)
131 views4 pages

Computer Engineering Department TED University: CMPE 252 - C Programming, Spring 2021 Lab 2

This document provides instructions for Lab 2 of the CMPE 252 - C Programming course. It outlines 3 parts that involve implementing functions to: 1) Circularly shift an array from left to right. 2) Compare two arrays and return values based on their equality or the first differing element. 3) Circularly shift an array until it is in its maximum configuration by comparing shifts. Skeleton code files are provided for each part, and the tasks involve filling in the missing function definitions while keeping the main functions intact. Sample runs are included to demonstrate expected behavior.

Uploaded by

mert
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

Computer Engineering Department

TED University

CMPE 252 - C Programming, Spring 2021


Lab 2
In this lab, you will use the following functions to be implemented for the prelab.
void readInput(int arr[], int *nPtr); // reads numbers from the standard input into
arr, and stores the number of read elements in the memory cell pointed to by nPtr

void printNumbers(const int arr[], int n); // prints the elements in arr[0..(n-1)]

Part 1 (30 points)

Implement the following function in skeleton code lab2part1.c:


// Circularly shift elements of arr from left to right where last element of arr is
// shifted the first position of arr.
// Size of arr is n.
void circularShiftFromLeftToRight(int arr[], int n);

Your task in this part to fill in the missing function definitions in skeleton code lab2part1.c.
main function will stay as it is.

Sample Run:
Computer Engineering Department

TED University

Part 2 (35 points)

Implement the following function in skeleton code lab2part2.c:


// Let n be the minimum of n1 and n2 where n1 and n2 are the number of elements in
// arr1 and arr2, respectively.
// Compare corresponding elements of arr1 and arr2 at each of the first n positions.
//
// If arr1 and arr2 has the same value in each position:
// Return 0 if n1 == n2
// Return 1 if n1 > n2
// Return -1 if n1 < n2
//
// If arr1 has a larger value than arr2 considering the first position from the
// beginning at which arr1 and arr2 have a different value:
// Return 1
//
// If arr1 has a smaller value than arr2 considering the first position from the
// beginning at which arr1 and arr2 have a different value:
// Return -1
int compareTwoArrays(const int arr1[], const int arr2[], int n1, int n2);

Your task in this part to fill in the missing function definitions in skeleton code lab2part2.c.
main function will stay as it is.

Sample Run:
Computer Engineering Department

TED University
Computer Engineering Department

TED University

Part 3 (35 points)

Implement the following function in skeleton code lab2part3.c:


// Circularly shift elements of arr from left to right until sequence of values in
// arr becomes the largest considering all sequence of values obtained by circularly
// shifting elements in arr.
void circularShiftUntilMaxArr(int arr[], int n);

• You need to use circularShiftFromLeftToRight function and compareTwoArrays function


while implementing circularShiftUntilMaxArr function.

Assume that arr can have at most 500 elements in it. Hint: If you need to declare a local array in function
circularShiftUntilMaxArr, you can set its size as 500.

Your task in this part to fill in the missing function definitions in skeleton code lab2part3.c.
main function will stay as it is.

Sample Run:

You might also like