This question requires m和n(m≤n)
writing a program for two positive integers to calculate the sequence sum
m 2 + 1 / m + (m + 1) 2 + 1 / (m + 1) +… + n 2 + 1 / nm^{2}+1 /m+(m+1)^{2}+1/(m+1)+...+n^{2}+1/nm2+1/m+(m+1)2+1/(m+1)+⋯+n2+1/n
Input format:
Enter two positive integers on one line, m和n(m≤n)
separated by spaces.
Output format:
In one line, sum = S
output the partial sum value in the format of " " S
, accurate to six digits after the decimal point. The title guarantees that the calculation result does not exceed the double precision range.
Input sample:
5 10
Sample output:
sum = 355.845635
Code:
# include <stdio.h>
# include <stdlib.h>
int main() {
int m,n,i;
double sum = 0.0;
scanf("%d %d",&m,&n);
for (i=m;i<=n;i++) {
sum += (i * i);
sum += (1.0 / i);
}
printf("sum = %.6lf",sum);
return 0;
}
Submit screenshot:
Problem-solving ideas:
There is nothing to say about this question, just pay attention to the traversal range of the loop