Problem: Write a program with a loop that lets theuser enter a series of integer
ID: 3611058 • Letter: P
Question
Problem: Write a program with a loop that lets theuser enter a series of integers. The user should enter -99 tosignal the end of the series. After all the numbers have beenentered, the program should display the largest and smallestnumbers entered. I have built the program but the problem I am having isgetting it to display the largest and smallest numbers entered. Ihave tried to use the Max and Min functions but since the user isable to enter as many numbers as they want, this is not working forme. How do I write a program to display the largest and smallestnumbers when I don't know what the numbers will be or how manynumbers will be entered? Please HELP!! Problem: Write a program with a loop that lets theuser enter a series of integers. The user should enter -99 tosignal the end of the series. After all the numbers have beenentered, the program should display the largest and smallestnumbers entered. I have built the program but the problem I am having isgetting it to display the largest and smallest numbers entered. Ihave tried to use the Max and Min functions but since the user isable to enter as many numbers as they want, this is not working forme. How do I write a program to display the largest and smallestnumbers when I don't know what the numbers will be or how manynumbers will be entered? Please HELP!!Explanation / Answer
JUST A SUGGESTION. read nums into an array, then use a bubblesort (the easiest to implement) to sort the numbers, then simplyprint the number in the first index and the last index. here issome code for a bubble sort. remember this sort is good for smallamounts of data. less than 1000. I doubt that you will have to usemore. play with this program, I think you will find this to be agood solution. #include <stdio.h>#include <iostream.h>void bubbleSort(int *array,int length)//Bubble sort function{int i,j;for(i=0;i<10;i++){for(j=0;j<i;j++){if(array[i]>array[j]){int temp=array[i]; //swaparray[i]=array[j];array[j]=temp;}}}}void printElements(int *array,int length) //print array elements{int i=0;for(i=0;i<10;i++)cout<<array[i]<<endl;}void main(){int a[]={9,6,5,23,2,6,2,7,1,8}; // array to sort, you can make this an empty array. int array[size]; size = nElems; then an insertMethod: insert(int item){array[item]; nElems++;}bubbleSort(a,10); //call to bubble sortprintElements(a,10); // print elements} 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.