满意答案
qq719185926
2013.04.07
采纳率:55% 等级:12
已帮助:8951人
1、函数fun的功能是:计算 f(x)=1+x+x*x/2!+x*x*x/3!+、、、+x*x*(n个)/n!直到小于十的﹣6次方直到 小于 。若x=2.5,函数值为:12.182494。 #include
#include
double fun(double x)
{ double f, t;
int n; f = 1.0+x;
t = x;
n = 1;
do {
n++; t*= x/n; f+= t;
} while (fabs(t) >= 1e-6);
return f;
}
void main()
{ double x, y;
x=2.5;
y = fun(x);
printf("\nThe result is :\n");
printf("x=%-12.6f y=%-12.6f \n", x, y);
}
2、函数fun的功能是:利用插入排序法对字符串中的字符按从小到大的顺序进行排序。插入法的基本算法是:先对字符串中的两个元素进行排序。然后把第三个字符插入到前两个字符中,插入后前三个字符依然有序;再把第四个字符插入到前三个字符中,……。待排序的字符串已在主函数中赋予。#include
#include
#define N 80
void insert(char *aa)
{ int i,j,n; char ch; n=strlen(aa);
for( i=1; i
j=i-1;
while ((j>=0) && ( ch
{ aa[j+1]=aa[j];
j--;
}
aa[j+1]=ch;
}
}
void main( )
{ char a[N]="QWERTYUIOPASDFGHJKLMNBVCXZ";
int i ;
printf ("The original string : %s\n", a);
insert(a) ;
printf("The string after sorting : %s\n\n",a );
}
00分享举报