[SOLVED] CMPSC311 - Assignment #1 - C Programming Basics

30.00 $

Category:

Description

5/5 - (3 votes)

Introduction to Systems Programming

 

In this assignment you will write simple functions in C. The purpose of this assignment is to assess your basic programming skills. You should have no difficulty in completing this assignment. If you do experience difficulty, then you should take some time to brush up on programming.

.

Below are the functions you need to implement:

  1. largest: Takes an array of integers and the length of the array as input, and returns the largest integer in the array. You can assume that the input array contains at least one element.
  2. sum: Takes an array of integers and the length of the array as input, and returns the sum of the integers in the array.
  3. swap: Takes a pointer to two integers and swaps the values of integers.

1

  1. rotate: Takes a pointer to three integers and rotates the values of integers. For example, if the inputs are pointers to integers a, b, and c, then after a call to rotate, c contains the value of b, b contains the value of a, and a contains the value of c.
  2. sort: Takes a pointer to an array of integers and the length of the array as input and sorts the array. That is, after a call to sort the contents of the array should be ordered in ascending order. You can implement any sorting algorithm you want but you have to implement the algorithm yourself—you cannot use sort functions from the standard C library. We recommend using something simple, such as Bubble sort or Selection sort.
  3. doubleprimes: Takes an array of integers and the length of the array as input and doubles every prime element of the array. For example, if the input array contains [1, 7, -2], then after a call to doubleprimes the array will contain [1, 14, -2].
  4. negatearmstrongs: Takes an array of integers and the length of the array as input and negates every element of the array that is an Armstrong number. An Armstrong number (also called a Narcissistic number) is a number that is equal to the sum of its digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because it has 3 digits and 13 +53 +33 =153. Thus, if an input array contains [2, -153, 153], then after a call to negatearmstrongs the array will contain [2, -153, -153].

You are encouraged to write helper functions to simplify the implementations of the above functions. You should, however, not use a library function and implement all helper functions yourself. For example, if you need a function to raise number a to power b, you should implement that function yourself.