Read the input sequence of numbers until the end of the file. Then, count the number of integers and compute their sum.
Algorithm implementation
Read the input sequence of numbers until the end of the file. The variable stores the count of numbers, and the variable stores their sum.
c = s = 0;
while (scanf("%d", &x) == 1)
{
c++;
s = s + x;
}Print the count of numbers and their sum.
printf("%d %d\n", c, s);Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int c = 0, s = 0;
while(con.hasNextInt())
{
int x = con.nextInt();
c++;
s = s + x;
}
System.out.println(c + " " + s);
con.close();
}
}Python implementation
Read the input sequence of integers into the list .
lst = list(map(int, input().split()))Print the count of integers in the list and their sum.
print(len(lst), sum(lst))