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

In C programming, Ask the user how many numbers they would like generated. Your

ID: 3662098 • Letter: I

Question

In C programming, Ask the user how many numbers they would like generated. Your program will then generate that many numbers (between 0 and 1000, inclusive) into an array of the same size. Find the smallest and largest numbers in the array, printing out the values of those numbers in the array. Then, find the sum and average of the numbers in the array. Finally, print out the entire array to verify. You MUST use functions where appropriate! Here is an example out put.

example output: How many? 30 max: 981 sum: 17172 avg: 572 Pos Val I 924 2 356 811 741 5 I 817 887 381 92 460 333 I 886 12 607 13 891 15 688 16 179 17 I 794 18 590 19 541 20 407 21 I 927 22 256 23 981 461 25 311 26 772 27 343 I 842 2B 29 I 650

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int small(int a[100],int n); //function to find the smallest value
int large(int a[100],int n); //function to find the largest value


int main() {
int c, n,m,smallest,largest,sum,avg;;
time_t t;

time(&t);

//Convert t to a unsigned integer.

srand((unsigned int) t);
printf("How many?");
   scanf("%d", &n);
   int a[n];

for (c = 1; c <= n; c++) {
       //generate the random number and store in array
    a[c-1] = rand() % 100 + 1;
}

sum=avg=a[0];
   smallest=small(a,n); // call the function small
   printf("min: %d ",smallest); // print the min value

largest=large(a,n); // call the function large
printf("max: %d ",largest); // print max value

   for(int i=1;i<n;i++){
           // calculate total of array
           sum=sum+a[i];}
   printf("sum: %d ",sum); // print sum of array
   printf("avg: %d ",sum/n); // print avg of array

printf("Pos    | value ");
for(int i=0;i<n;i++){ // print the array
          printf("%d      | %d ",i,a[i]);}


return 0;
}
int small(int a[100],int n){   // definition of function small
    int s=a[0];
    for(int i=1;i<n;i++){
          if(a[i]<s){
                           s=a[i];}}
                           return s;}
int large(int a[100],int n){   // definition of function large
    int l=a[0];
    for(int i=1;i<n;i++){
          if(a[i]>l){
                           l=a[i];}}
                           return l;}