i am trying to do a program that reads in an arbitrary number of lists of integers.
SPECIFICS
-A valid list of integers consists of AT MOST (could be less than) 20 integers.
-You can be given less than 20 numbers.
-You might be given more than 20 numbers. This means that the list is invalid.

If a list has 20 integers or less, you should then:
-Print what number list this is (1st one you read, second, etc.)
-Print the list in the order it was given
-Print the sum
-Print the average
-Print the list sorted from least to greatest

Check if there is another list to process; if yes, there will be an asterisk character.
-Any character that is not an asterisk means there are no more lists to process.

i wanted to know if i am off the the right start. still fairly new to programing so any advise as to what direction to head would be appreciated.

``````#include <stdio.h>

#define SIZE 20

int main(void){
int i = 0;
int arr[SIZE];
int n;

while (i < SIZE){
int n = scanf("%d", &arr[i]);
i++;
}
if (n == 1){
printf("%d\n", arr[i]);
}``````

From the description I would think you need to read the numbers from a text file, not from the keyboard.

## All 3 Replies

From the description I would think you need to read the numbers from a text file, not from the keyboard.

Also, how do you know when you've reached the end of a list?

From your given description,you need to make a file from which you will get the list of integers. Then check the list contains 20 integers or more. For that you need to find end of the list. That will help you to count the number of integers. Then you can perform all the operation like average, sum and sorting also.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.