Write a c program to calculate sum of square root from 1 to n number.
/**
* Write a c program to calculate sum of square root from 1 to n number.
**/
#include <stdio.h>
#include <math.h>
int main() {
int n;
scanf("%d", &n);
float sum = 0.f;
for (int i = 1; i <= n; i++) {
sum += sqrtf((float)i);
}
printf("%0.4f", sum);
return 0;
}
Comments
Leave a comment