Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

need help!! I am confused with lists and user inputs to make into a list

0 votes
asked May 7, 2020 by A Jackson (120 points)
How do I take a users integers that they entered and put them into a list
then with that list print the maximum and then the minimum integers within that list?

1 Answer

0 votes
answered Jun 6, 2020 by Tushar Goswami (190 points)
For python:

list1 = map(int, input().strip().split()) #within a single line, space separated value
list1 = []
for ele in range(int(input())):
    list1.append(int(input())) #Within new line
print(min(list1), max(list1), end ='')

For C, C++, C#:

int n;
scanf("%d", &n);
int arr[n];
for (int i=0; i<n; i++)
{
scanf("%d", arr[i]);
}

int min = arr[0], max =arr[0];
for (int i=1; i<n; i++)
{
if(arr[i]>max) max = arr[i];
if(arr[i]<min) min = arr[i];
//You can use cin for C++
commented Jun 11, 2020 by Peter Minarik (86,680 points)
This is a C/C++ code. This code does not compile in C#.

Also, you want to do

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

otherwise, you get segmentation fault as you're not reading into the ith position in the arr array (i.e. to the memory address of the ith position in the array).
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...