Skip to content

Instantly share code, notes, and snippets.

@KeitetsuWorks
Created November 17, 2017 14:16
Show Gist options
  • Save KeitetsuWorks/d4cbbb2a92e240e9f7af4e62fb8c2c8d to your computer and use it in GitHub Desktop.
Save KeitetsuWorks/d4cbbb2a92e240e9f7af4e62fb8c2c8d to your computer and use it in GitHub Desktop.
q10182193340.c
/**
* @file q10182193340.c
*/
#include <stdio.h>
#include <math.h>
#define N 100
double Sn(int n)
{
/* 戻り値を浮動小数点型とし,数値を明示的に浮動小数点数とする */
return (3.0 * sqrt(3.0) / 16.0) * pow(4.0 / 9.0, n);
}
int main(void)
{
int n;
double sum = 0.0;
for (n = 1; n <= N; n++) {
sum += Sn(n);
printf("n = %d, sum = %f\n", n, sum);
}
sum = sum + sqrt(3.0) / 4.0;
printf("sum = %f\n", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment