C_运用do
源码:
# include <math.h>
# include <stdio.h> /* 数学函数库 */
int main()
{
/* 用s表示多项式的值,用t表示每一项的值 */
double s, t, x; // 此处用双精度声明变量
int n;
printf("please input x: ");
scanf("%lf", &x); // %lf 代表用双精度输入
/* 赋初值 */
t = x;
n = 1;
s = x;
/* 进行叠加运算 */
do
{
n = n + 2 ;
t = t * (-x*x)/((float)(n)-1)/(float)(n);
s = s + t;
} while (fabs(t)>=1e-8); // 本来是要大于0,但也可大于一个很小的数即可
printf("sin(%f) = %lf\n", x, s);
return 0;
}
相关文档:
源码:
# include <stdio.h>
int main()
{
/* 换行符'\n',用于输出换行 */
printf("How are you?\n");
printf("I am fine.\n\n");
/* 横向跳格符'\t',使跳到下一个输出区 */
  ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
int m, n, p;
i = 8;
j = 10;
k = 12;
/* 自增在操作数之前 */
  ......
源码:
# include <stdio.h>
int main()
{
/* 定义了一个无符号字符型变量,此变量只能用来存储无符号数 */
unsigned char result;
int a, b, c, d;
a = 2;
b = 4; ......
源码:
# include <stdio.h>
int main()
{
/* 定义字符型变量,并给它们付初值 */
char c1, c2, c3, c4, c5, c6, c7;
c1 = 'C';
c2 = 'h';
c3 = 'i';
c4 = 'n';
& ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
/* 变量i从0到4,表示所画菱形图的第一至第五行 */
for(i = 0; i <= 4; i++)
{
/* ......