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

Write a program to determine the length of bursts of zero\'s in a list of N numb

ID: 3596882 • Letter: W

Question

Write a program to determine the length of bursts of zero's in a list of N numbers stored in an array. The program should record the length of the bursts of zero's in another array. The program should then print the lengths of the bursts. Using this second array with the lengths of the bursts, it should also compute and print the following: the average length of the bursts, the minimum burst length, the maximum burst length, and the total number of zeros (the sum of the burst lengths) Your program should 1. Prompt the user for the size of the list (N). Then it should prompt the user to enter N numbers and store them into an array called list. Note, you should specify the maximum size of N allowed (based on how large you declare your array) Given N and list, your program should compute the lengths of the bursts of zeros and store them in an array called BurstLengths. After computing and storing the burst lengths you should terminate your BurstLengths array with a sentinel (1). Use a for loop in this step Given the BurstLengths array with a sentinel (-1), use a while loop to print the list of burst lengths. Format this nicely in a table with headings. 2. 3. . Given the BurstLengths array with a sentinel (-1), compute and then print the following information a. b. c. d. Average burst length Minimum burst length Maximum burst length Total number of zeros

Explanation / Answer

#include <stdio.h>

int main() {

int n,i,j,count,ind;

printf("Enter length of array ");

scanf("%d",&n);

int list[n],BurstLengths[n/2+2];

//input array

printf("Enter %d values ",n);

for(i=0;i<n;i++)

{

scanf("%d",&list[i]);

}

//finding BurstLengths

ind=0;

for(i=0;i<n;i++)

{

if(list[i]==0)

{

count=0;

for(j=i;j<n;j++,i++)

{

if(list[j]==0)

count++;

else

break;

}

BurstLengths[ind]=count;

ind++;

}

}

BurstLengths[ind]=-1;

//printing BurstLengths in while

i=0;

while(BurstLengths[i]!=-1)

{

printf("%d ",BurstLengths[i]);

i++;

}

//finding other info

float averagebursts=0;

int totZeroes=0,minBursts=32767,maxBursts=0,numofbursts=0,avg=0;

for(i=0;BurstLengths[i]!=-1;i++)

{

if(maxBursts<BurstLengths[i])

maxBursts = BurstLengths[i];

if(minBursts>BurstLengths[i])

minBursts=BurstLengths[i];

  

avg+=BurstLengths[i];

numofbursts++;

}

averagebursts = (float)avg/numofbursts;

//print in table other info  

printf(" Type Count ");

printf("Average %f ",averagebursts);

printf("Minimum %d ",minBursts);

printf("Maximum %d ",maxBursts);

printf("Total %d ",numofbursts);

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