Explore BrainMass

Pickup 10 Numbers and Store Array Using Function fillAr

Using c-language programming (not C++):

Write a complete program to do the following specification:

1. Pickup 10 numbers and store it in an array using function fillArray.
2. Print the content of array with the message "Array not sorted" using printArray function.
3. Copy array a into array b using copyArray(a,b,10) function.
4. Sort array b in ascending order using sortArray(b,10) function.
5. Print array b with message "sorted array" using printArray
6. Pickup 10 numbers and store it in array c.
7. Find largest, smallest, and median values of array c and print them.
8. Print largest number of two arrays a,c and specify which array contains it.
9. Your program should ask for a number and print "YES" if the number is in array a, otherwise print "not found"

Solution Preview

// 184948.c

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

// Define fillArray function to create an array of 10 random integers
void fillArray(int array[]) {
int i;
for (i=0; i<10; i++) {
array[i] = rand();

// Define printArray to print out an array
void printArray(int array[], char *message) {
int i;
printf("%s: [", message);
for (i=0; i<10; i++) printf("%d ", array[i]);

// Define copyArray to copy from one array to the other
void copyArray(int arrayA[], int arrayB[], int length) {
int i;
for (i=0; i<length; i++) arrayB[i] = arrayA[i];

// Define sortArray to sort an array in ascending order
void sortArray(int array[], int length) {
int i,j;
int temp;
for (i=0; i<length; i++) {
for (j=i; j<length; j++) {
if ...

Solution Summary

This Solution provides the code requested in the question.