# Program 1 In Program1.c, write the function int foo(int* a, int *b...

## Question

Program 1
In Program1.c, write the function int foo(int* a, int *b, int c) that is supposed to do the following:

Increment a Decrement b Assign (a - b) to c
Return the value of c.

In the main function, declare three integers x, y, z, and assign to them random integer values in the interval [0,10], using rand(). Print the values of x, y, z. Call foo() by appropriately passing x, y, z, as arguments.
Print out the values of x, y, z, after foo(), as well as the value returned by foo().

Printing x, y, z before calling foo() = 1 point Printing x, y, z after foo() = 4 points
Return value of foo() = 4 points
Comparison of the return value of foo() and z = 1 point

Program 2
In Program2.c, write the following functions and demonstrate their functionality by calling them (in the given order) from the main function:

struct student* allocate() that allocates memory for 10 students, and returns the pointer.
void generate(struct student* students) that generates random initials and random scores for each of the 10 students, and stores them in the array students. To generate two initial letters of a student you may use the following code: char c1 = rand()%26 + 'A'; char c2 = rand()%26 + 'A'; where % indicates the modulo operation. The random score for each student should take values in the interval [0, 100]. void output(struct student* students) that prints the initials and scores of all students.
void summary(struct student* students) that prints the minimum score, maximum score and average score of the 10 students.
void deallocate(struct student* students) that frees the memory allocated to students. Check that
students is not NULL before you attempt to free it.

Program 3
In Program3.c, write the function void sort(int* numbers, int n) to sort an array of n integers in the ascending order. In the main function:

Declare an integer n. Allocate memory for an array of n integers using malloc. Fill this array with random numbers using rand(). Make sure that you can handle the case when n=0.
Print the contents of the array.
Pass this array along with n to sort().
Print the contents of the sorted array after sort().

Program 4
In Program4.c, we will consider the structure student from Program2.c. Modify the function sort() from Program3.c to sort an array of n students based on their initials. The function prototype is void sort(struct student* students, int n). In sort(), if two students have the same first initial, you should compare their second initial. As in Program2.c, initials and scores of students are to be generated randomly by
rand(). Make sure that you can handle the case when the user provides input n=0.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>

int foo(int* a, int* b, int c){
/* Increment a */
(*a)++;

/* Decrement b */
(*b)--;

/* Assign a-b to c */
c = (*a) - (*b);
/* Return c */
return c;
}

int main(){
/* Declare three integers x,y and z and initialize them randomly to values in [0,10] */
int x, y, z;
x = rand() % 11;
y = rand() % 11;
z = rand() % 11;

/* Print the values of x, y and z */
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("z = %d\n", z);

/* Call foo() appropriately, passing x,y,z as parameters */
int val = foo(&x, &y, z);

/* Print the values of x, y and z */
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("z = %d\n", z);

/* Print the value returned by foo */
printf("the value returned by foo: %d\n", val);...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$32.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.