answersLogoWhite

0


Best Answer
  1. import java.util.Scanner;
  2. public class average {
  3. static int i=0;
  4. static double sum = 0;
  5. static double average = 0;
  6. public static double calcSum(double sum){
  7. double count;
  8. Scanner input = new Scanner(System.in);
  9. while(i < 5){
  10. count = input.nextDouble();
  11. sum = sum + count;
  12. i++;
  13. }
  14. return sum;
  15. }
  16. public static double calcAverage(double average){
  17. double sum = calcSum(sum);
  18. average = calcSum(sum) / 5;
  19. return average;
  20. }
  21. public static void main(String[] args) {
  22. System.out.println("Please enter 5 numbers.");
  23. System.out.println("Sum is: "+calcSum(sum));
  24. System.out.println("Average is: "+calcAverage(average));
  25. }
  26. }
User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago


sumOfOneToN(int n)
{
if(n <= 1)
return n;
else
return( n + sumOfOneToN( n - 1 ) );

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Numbers from 1 to n can be summed up in Perl using the code below: BEGIN { $/ = "n"; $ = "n"; } LINE: while (defined($_ = )) { chomp $_; $sum += $_; } sub END { print $sum; } -e syntax OK

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you sum up numbers from 1 to n?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the sum of the first 102 counting numbers?

If you want to sum up numbers 1 to N, you can do it this way. Sum = (N+1)*(N/2).The reason this works: say you want to sum up 1 through 10. You have 10+1, 9+2, ..., 6+5. Each of these equals 11 [N+1]. You added 11 five times (N/2). Sum of 1 to 102 = (102+1)*(102/2) = 103*51 = 5253. You can check it by summing up the numbers with a spreadsheet.


What are the three consecutive numbers that sum up to 468?

let the three numbers be: n-1, n, n+1 their sum is equal to 3n 468=3n which means that n=156 the three numbers are 155, 156, 157


How do you get the sum of consecutive cubed numbers?

The sum of the first n cubed numbers is: [n*(n+1)/2]2 which is the same as the square of the sum of the first n numbers.


If you add up all the numbers from 1 to 1000 what do you get?

Sum of first n numbers = n/2(n +1) = 500 x 1001 = 500500


How do you calculate the sum of all numbers from 1 through 61?

The sum of the first "n" numbers is equal to n(n+1)/2.


Create a program that will display the sum of all numbers from 1 up to the input number?

to print the sum of first ten numbers:- void main() {int i,sum; sum=0; while(i&lt;=10) sum=sum+i; i=i+1; } printf("The sum is : %d",sum); }


What is the sum of the first 22 odd numbers?

The sum of a sequence is given by sum = n/2(2a + (n-1)d) where: n = how many a = first number of sequence d = difference between terms of sequence. For the first 22 odd numbers these are: n = 22 a = 1 d = 2 &rarr; sum = 22/2(2&times;1 + (22 - 1)&times;2)) = 22&sup2; = 484 The sum of the first n odd numbers is always n&sup2;: sum = n/2(2&times;1 + (n-1)2) = n/2(1 + (n-1))&times;2 = n(n) = n&sup2;


What is the sum of the numbers 1 through 35?

To sum numbers 1 through N, use this formula: (1 + N)*N/2, so (1+35)*35/2 = 630.


What is the sum of the first 100 even numbers?

n*(n+1)=sum 100*(100+1)=10100


What is the Sum of first n natural numbers?

int sum = 0; int i; for(i = 0; i &lt; n; ++i) { sum += i; }


What is the sum of the numbers from 1 to 100?

Sum of first n natural numbers is (n) x (n + 1)/2 Here we have the sum = 100 x (101)/2 = 50 x 101 = 5050


Write algorithm compute sum of square of N numbers?

1. Design an algorithm to compute sum of the squares of n numbers?