Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note: Must be in C code only and please write in a fashion that I can copy and p

ID: 3544533 • Letter: N

Question

Note: Must be in C code only and please write in a fashion that I can copy and paste directly to my compiler.  I am using Visual Studio 10.


Assignment:

In this assignment you will write a small C program to a) receive integer values from the user, and store those values as an array, b) compute the minimum, c) maximum and d) average value.


The program will display a menu with the following options:
1) Enter a new set of values
2) Find the minimum value entered
3) Find the maximum value entered
4) Find the average value
5) Exit
The program should accept up to 10 values. If user select a number from 1-4, a function should be called. All these functions should receive at least two parameters a) an array of integers, and b) the size of the array. Option 2 and 3 must return an integer value, while option 4 must return a float data type.

Explanation / Answer

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

void getVal(int arr[10], int *size)
{
    *size = 0;
    int temp;
    printf("Enter up to 10 integers(-99 to stop) ");
    while((*size) < 10)
    {
        printf("Enter integer number %d: ", (*size)+1);
        scanf(" %d", &temp);
        if(temp == -99)
            break;
        arr[*size] = temp;
        (*size)++;
    }
}

int findMin(int arr[10], int size)
{
    int min, i;
    min = arr[0];
    for( i = 1; i < size; i++){
         if(arr[i] < min)
             min = arr[i];
    }
    return min;
}

int findMax(int arr[10], int size)
{
    int max, i;
    max = arr[0];
    for( i = 1; i < size; i++){
         if(arr[i] > max)
             max = arr[i];
    }
    return max;
}

float findAvg(int arr[10], int size)
{
    int total = 0, i;
    for( i = 0; i < size; i++){
         total += arr[i];
    }
    return total/size;
}

int main()
{
int array[10];
int size;
int choice;
while(1)
{
//menu
printf(" 1)Enter a new set of values 2)Find the minimum value entered 3)Find the maximum value entered 4)Find the avrage value 5)Exit ");
printf("Choose an option: ");
scanf( "%d", &choice);
switch (choice)
{
    case 1:
         getVal(array, &size);
         break;
    case 2:
         printf("Minimum value is %d. ", findMin(array,size));
         break;
    case 3:
         printf("Maximum value is %d. ", findMax(array,size));
         break;
    case 4:
         printf("Average value is %f. ", findAvg(array,size));
         break;
    case 5:
         printf("Exiting program... ");
         exit(1);
    default: printf("Incorrect choice, please try again. ");
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote