随机函数c语言对打,C语言编程题

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

qq719185926

2013.04.07

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率: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分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值