Write an algorithm that reads in a list numbers one by one. Your algorithm shoul
ID: 3613671 • Letter: W
Question
Write an algorithm that reads in a list numbers one by one. Your algorithm should count how many zeros you see on the list before the first negative number, compute sum of all numbers before the first negative number. The list will have both positive and negative values and some zeros. Algorithm should stop counting and adding when you see the first negative number. There will be at least one negative number. At the end, print the count_of_zeros, sum and the average. For example if the input is 7,5,0,9,12,17,0,0,-1,2; the output should be 3,50, and 6.25 (50/8).Explanation / Answer
Dear.... Algorithm: STEP 1: Start STEP 2: Input Listsize N STEP 3: for i 0 to Ndo read List[i] end for STEP 4: sum=0,count_of_Zeros=0,count; STEP 5: fori 0 to N do if(List[i]<0) break; end if if(List[i]==0) count_of_Zeros++; end if sumsum+List[i]; count++ end for STEP 6: Averagesum/count STEP 7: Print count_of_Zeros STEP 8: Printsum STEP 9: PrintAverage STEP 10:Stop Hope this will helpyou....Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.