Witte a program to find the average of the first P multiples of an integer N
pea4518977:
Please marks as brainliest
Answers
Answered by
15
Answer:
Input : 10
Output : 5.5
1+2+3+4+5+6+7+8+9+10 = 5.5
Input : 7
Output : 4.0
1+2+3+4+5+6+7 = 4
Explanation:
Answered by
0
Answer:
static int calculate_sum(int a, int N) {
// Number of multiples
int m = N / a;
// sum of first m natural numbers
int sum = m * (m + 1) / 2;
// sum of multiples
int ans = a * sum;
return ans;
}
// Driver code
public static void main(String[] args) {
int a = 7, N = 49;
System.out.println("Sum of multiples of " + a +
" up to " + N + " = " +
calculate_sum(a, N));
}
}
#SPJ3
Similar questions