for(int i = 1; i < 100; i+=2) { System.out.println(i); }
Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.
public class sum { public static void main(String args[]){ int sum=0; for(int i=1;i<=10;i++){ sum=sum+i; } System.out.println(sum); } }
int i, sum = 0; for (i=0; i<20; i+=2) sum+=i;
$n = 10*(1+10)/2;
for(int i = 1; i < 100; i+=2) { System.out.println(i); }
sum = 0; for (int i = 12; i
Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.
write an assembly language program to find sum of N numbers
// numbers to work with double[] nums = {1, 2, 3, 4.5, 5.5, 6, 7.5, 8, 9, 10}; double sum = 0; // total sum for (int i = 0; i < nums.length; ++i) { sum += nums[i]; } // final average final double mean = (sum / nums.length);
#include
public class sum { public static void main(String args[]){ int sum=0; for(int i=1;i<=10;i++){ sum=sum+i; } System.out.println(sum); } }
The following is for F95 and later (due to the use of intrinsic SUM ): My assumptions: -Your numbers are integers -Your numbers are stored in an array -The numbers you are describing are 0-100 program findSum !I assumed integer, replace this with your data type integer, dimension(100) :: numbers integer :: sumOfNumbers !We populate an array with our numbers !Replace this with your numbers do i=1,(size(numbers)+1) numbers = i end do !We find the sum of those numbers sumOfNumbers = sum(numbers) !We write out the sum to prompt write(*,*) 'Sum is: ', sumOfNumbers end program findSum
int i, sum = 0; for (i=0; i<20; i+=2) sum+=i;
Since there is an infinite set of prime numbers the answer would be infinity.
import java.util.Scanner; public class Sum { public static void main(String args[]) { int sum=0; Scanner s=new Scanner(System.in); for(int i=0;i<10;i++) { System.out.printf("enter a number:"); sum+=s.nextInt(); }//end of for }//end of main }//end of class
$vi sum.sh echo "enter the 1st no." read num1 echo "enter the 2nd no." read num2 sum= 'expr $num1 + $num2' echo "sum of the numbers is $sum"