C语言题目求解

Exercise6-1已给程序:•statistics.h•my_pointerFun.h需要完成并提交的程序:•statistics... Exercise 6-1
已给程序:
• statistics.h
• my_pointerFun.h
需要完成并提交的程序:
• statistics.c
• my_pointerFun.c
• my_pointerFun.h
• main.c

1. 完成函数my_pointerFun(顾名思义,指针函数),该函数需有两个整型参数(x and y, in this order)且没有返回值. 要求完成的功能在my_pointerFun.h有详细描述。注意在文件头需进行正确的函数声明。
2.按照statistics.h 中的要求完成statistics.c文件
3. 写出测试程序main.c以测试你的程序是否正确。
注意:
• my_pointerFun部分占成绩的20%,main 部分占%10, statistics 部分占70%。
• 这里考察的是将指针作为函数参数问题。

my_pointerFun.h :

#ifndef _POINTERFUN_H

#define _POINTERFUN_H

/** Set values by pointers

* If param x and y point to the same variable, output value 1 + 2 to it, otherwise:

* param x pass-by-pointer: output value 1

* param y pass-by-pointer: output value 2

**/

void my_pointerFun( double* x, double* y);

#endif

statistics.h :

#ifndef C_STATISTICS_H

#define C_STATISTICS_H

#include <stddef.h>

/** Read doubles from stdin and calculate statistics of them.

* Reading terminates after enough values have been read or when reading a value fails.

* If no values are read, nothing is returned via min/max.

* param count pass-by-pointer: input max amount of values to read, output actual count of values read, cannot be NULL

* param min pass-by-pointer: input none, output min value, nothing if NULL

* param max pass-by-pointer: input none, output max value, nothing if NULL

* param sum pass-by-pointer: input old sum, output updated sum, nothing if NULL

* return the last value read successfully (0.0 if no values were read)

**/

double statistics(size_t* count, double* min, double* max, double* sum);

#endif
展开
 我来答
mkr67n
2020-02-24 · TA获得超过229个赞
知道小有建树答主
回答量:192
采纳率:77%
帮助的人:31.9万
展开全部

第一个问题:两单引号间夹一个字符意味着把中间的字符转换成ASCII码,对于char类型,其实要用ASCII码赋值,换句话说其实ch = 'a';等价于ch = 97;,所以'a'事实上已经把a转化为ASCII码的数字编号,可以用于数字加减。

第二个问题:用了Dev C++和VisualStudio测试过都是非法的,原因大概是因为\0和空还是有本质上的区别。

'\0'是字符串的结束标志,虽然它的意义上是空,我们也可以当做空来理解,然而对于计算机而言,它并不是空,而是一个确确实实存在的标识符,它告诉编译器字符串在这里结束了。

而'',则是实实在在的空,它里面什么都没有,是真的没有(无论对于你而言还是计算机而言),所以编译器无法读取中间的数据,于是就报错了(我反而觉得如果存在不报错的编译器,是该编译器的一种优化,它就应该报错才对)

另外测试过char ch='\0';是正确的,用转义字符可以成功地录入“空字符”。

百度网友8b58de0
2019-03-15 · TA获得超过945个赞
知道小有建树答主
回答量:1079
采纳率:83%
帮助的人:283万
展开全部
//这哪里是考编程,根本是在考英文。不知道我理解正确了吗,代码如下
//文件:my_pointerFun.c
#include "my_pointerFun.h"
void my_pointerFun(double* x, double* y)
{
if (*x==*y)
{
*x=1;
*y=2;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//文件:statistics.c
#include <stdio.h>
#include <stdlib.h>
#include "statistics.h"
double statistics(size_t* count, double* min, double* max, double* sum)
{
double *in;
size_t i;
if(!count||!min||!max||!sum) return 0;
in=(double *)malloc(*count*sizeof(double));
if(!in) return 0.0;
for(i=0;i<*count;i++)
{
if(scanf("%lf",&in[i])!=1) return 0;
}
*max=in[0];
*min=in[0];
for(i=0;i<*count;i++)
{
if(in[i]>*max) *max=in[i];
if(in[i]<*min) *min=in[i];
}
free(in);
*sum=*count;
return *count;
}
////////////////////////////////////////////////////////////////////////
//文件:main.c
#include <stdio.h>
#include <stdlib.h>
#include "my_pointerFun.h"
#include "statistics.h"
void main()
{
double x,y;
double max,min,sum;
x=1.1;
y=1.2;
my_pointerFun(&x,&y);
printf("x=%.1f,y=%.1f\n",x,y);
x=1.1;
y=1.1;
my_pointerFun(&x,&y);
printf("x=%.1f,y=%.1f\n",x,y);
size_t size=2;
sum=1.01;
if(statistics(&size,&min,&max,&sum)!=0)
{
printf("min=%.2f,max=%.2f,sum=%.2f\n",min,max,sum);
}
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式