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

This is C coding syntax. Please complete the steps displayed below: Ask the user

ID: 3874743 • Letter: T

Question

This is C coding syntax. Please complete the steps displayed below:

Ask the user how many numbers they would like generated. Your program will then generate that many numbers (between 0 and 1000) into an array of the same size. Find the smallest and largest numbers in the array, printing out the values and locations 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. Requirements: *x You MUST use functions where appropriate! Output MUST be formatted as below (numbers, spacing, etc.) Count the spaces, make sure it's correct. Make sure you include both 0 and 1000 in your random generation

Explanation / Answer

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


int main(void)
{
int n;
printf(" enter the integer: ");
scanf("%d",&n);
int array[n];
int max=0,max_index=0;
int min=0,min_index=0;
int sum=0;
float avg;
   // This program will create different sequence of
   // random numbers on every program run

   // Use current time as seed for random generator
   srand(time(0));

   for(int i = 0; i<n; i++)
   array[i]=rand()%1000;//generate random number b/w 0 to 1000.
  
   for(int i=0;i<n;i++)
   {
   if(array[i]>max)
   {
   max=array[i];
   max_index=i;
   }
   }
   min=array[0];
   for(int i=0;i<n;i++)
   {
   if(min>array[i])
   {
   min=array[i];
   min_index=i;
   }
   }
   for(int i=0;i<n;i++)
   sum=sum+array[i];//sum of n random numbers
   avg=sum/n;//avg of N random numbers
   printf("Min :%d Pos :%d ",min,min_index);
printf("Max :%d Pos :%d ",max,max_index);
printf("Sum :%d ",sum);
printf("Avg :%d ",avg);
printf("Pos|Val ");
printf("------- ");
for(int i=0;i<n;i++)
printf("%d | %d ",i,array[i]);
}

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