import java.io.*;
public class sum{
public static void main(String[] args) {
try{
System.out.print("Enter 10 numbers: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] input=new int[10];
int a,total=0;
for(a=0;a<10;a++) {
System.out.println();
input[a]=Integer.parseInt(br.readLine());
}
for(a=0;a<10;a++) {
total+=input[a];
}
System.out.println("The sum of the numbers is "+total);
}catch(Exception e) {
e.printStackTrace();
}
}
}
Chat with our AI personalities
to print the sum of first ten numbers:- void main() {int i,sum; sum=0; while(i<=10) sum=sum+i; i=i+1; } printf("The sum is : %d",sum); }
Sum = Sum + first number Sum = Sum + second number Sum = Sum + third number Average = 1/3 x Sum
#include<iostream> unsigned sum_of_digits(unsigned num) { unsigned sum = 0; do { sum += num%10; } while (num/=10); return sum; } int main() { unsigned number = 12345; unsigned sum = sum_of_digits (number); std::cout << "Sum of digits in " << number << " is " << sum << std::endl; }
The sum of the two numbersis 105.7 the difference of the two number is19
you can use the condition statement like for(i=0:i<=10;i++)