The process of finding the largest number (i.e.. the maximum of a group of numbe
ID: 3796131 • Letter: T
Question
The process of finding the largest number (i.e.. the maximum of a group of numbers) is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. Write (1) a pseudocode program and thon (2) a program in C that inputs a series of 10 non-negative numbers and determines and prints the largest of the numbers. A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed) The current number input to the program The largest number found so farExplanation / Answer
Pseudocode
Step 1: Read 10 numbers from input
Step 2: Initialize largest with first number which was entered
Step 3: Initialize counter with 0
Step 4: Repeat following code till counter is less than 10
increment counter by 1
IF number is greater than largest
SET largest to be equal to number
Step 5: Print largest
Step 6: Exit
C Program
#include<stdio.h>
int main()
{
int a[10]; //Array to store all the numbers
for(int i=0;i<10;i++) //STEP 1: Read 10 numbers from input
scanf("%d",&a[i]);
int largest=a[0]; //Step 2: Initialize largest with first number which was entered
int counter=0; //Step 3: Initialize counter with 0
int number;
while(counter<10) //Step 4: Repeat following code till counter is less than or equal to 10
{
counter = counter + 1; //increment counter by 1
number = a[counter]; //Setting number to next entered number
if(number>largest) //IF number is greater than largest
largest = number; //SET largest to be equal to number
}
printf("%d",largest); //Step 5: Print largest
return 0; //Step 6: Exit
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.