Created
November 17, 2017 14:16
-
-
Save KeitetsuWorks/d4cbbb2a92e240e9f7af4e62fb8c2c8d to your computer and use it in GitHub Desktop.
q10182193340.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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