孔令辉对阵刘国梁:c语言编程题

来源:百度文库 编辑:高考问答 时间:2024/05/06 12:15:55
***************************************************************/
#include <math.h>
#include <stdio.h>
#include <string.h>
#define CODE 55
#define M 55
/************************************************************************
3。下述函数 double fun(double x, int n) 的功能是计算如下
公式的值:(其中 x^n 表示 x 的 n 次方,n! 为 n 的阶乘)
x x^2 x^3 x^4 x^n
fun( x, n )= - —— + ——— - ——— + ——— - … ———
1! 2! 3! 4! n!
前 n 项之和,其中 n≥1 。
例如:fun( 6.66, 8 ) = 40.955
fun( 6.66, 15 )= -1.511
(提示:若第 i-1 项的值为 t ,则第 i 项的值为 -t*x/i )
***************************************************************/
double fun ( double x, int n )
/*=======================================================================*/
{
double y=0.0;

}

return y;

}
/*-----------------------------------------------------------------------*/

4/************************************************************************
编写函数:fun4( int a[], int b[], int na, int *nb ),其中 a 数组有 na个
元素(均为正整数)。函数 fun4 的功能是:找出 a 数组元素中所有大于 4 的
素数依次存入 b 数组中,在 nb 所指的单元中存入这些素数的个数。(数组下标
从 0 开始,不能改动 a 数组元素的值)。
例如:a 数组为:11, 13, 14, 12, 15, 16, 18, 19, 17, 110;
a 数组元素中大于 4 的素数有:11, 13, 19, 17;
则调用函数 fun4 后 b 数组为:11, 13, 19, 17;
且 *nb 的值为:4(即 b 数组共存入了4个元素)。
*************************************************************************/
void fun4( int a[], int b[], int na, int *nb )
{
/*=======================================================*/

/*-------------------------------------------------------*/
}
大侠们帮忙看一下啊,准备2级考试的
帮忙用C编出来 运行后答案正确就把积分给你拉

第1题:
#include <stdio.h>
#include <string.h>
int fun3(int a[],int n,int b[])
{
int j=0;
int i,k,tmp,ti;
/*选取a[]中的偶数放到b[]中,并用s记录偶数的个数*/
for (i=0;i<n;i++)
if (a[i]%2==0) b[j++]=a[i];
/*选择排序*/
for (i=0;i<j-1;i++)
{
ti=i;
for (k=i+1;k<j;k++)/*选出未排序的数据中的最小值的位置*/
if (b[ti]<b[k]) ti=k;
if (ti!=i) {tmp=b[ti];b[ti]=b[i];b[i]=tmp;}/*当前未排序的第一个数和最小值交换*/
}
return j;
}
int main()
{
int a[100],b[100];
int i,n;
/*输入数组a的数据,以0为结束*/
i=0;
do
scanf("%d",&a[i++]);
while (a[i-1]);
n=fun3(a,i-1,b);
/*输出*/
for (i=0;i<n;i++)
printf("%d ",b[i]);
}
---------------------------
第2题:
#include <stdio.h>
#include <string.h>
void fun4(char str1[], char t[])
{
int i,len;
len=strlen(str1);
for (i=len-1;i>=0;i--)
{
if (str1[i]>='a'&&str1[i]<='z') t[len-1-i]=str1[i]-'a'+'A';
else if (str1[i]>='A'&&str1[i]<='Z') t[len-1-i]=str1[i]-'A'+'a';
else t[len-1-i]=str1[i];
}
return;
}
int main()
{
char str1[200],t[200];
scanf("%s",str1);
fun4(str1,t);
printf("%s\n",t);
}

这个好难啊!!~~~~~~~~~~~~