用C语言编写程序计算圆周率
时间: 2024-05-15 09:17:16 浏览: 173
用c语言求圆周率
Sure, I can help you with that! Here is a simple program written in C language to calculate the value of pi:
```c
#include <stdio.h>
int main() {
int i, n = 10000;
double pi = 0.0;
for (i = 0; i < n; i++) {
pi += 4.0 / (1.0 + i * i);
}
printf("The value of pi is approximately: %.15f\n", pi/n);
return 0;
}
```
This program uses the Leibniz formula for pi to calculate its value. The more iterations you run, the more accurate the result will be.
阅读全文