c语言实验三参考答案-2012秋

上传人:第*** 文档编号:34088727 上传时间:2018-02-20 格式:DOC 页数:7 大小:80KB
返回 下载 相关 举报
c语言实验三参考答案-2012秋_第1页
第1页 / 共7页
c语言实验三参考答案-2012秋_第2页
第2页 / 共7页
c语言实验三参考答案-2012秋_第3页
第3页 / 共7页
c语言实验三参考答案-2012秋_第4页
第4页 / 共7页
c语言实验三参考答案-2012秋_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《c语言实验三参考答案-2012秋》由会员分享,可在线阅读,更多相关《c语言实验三参考答案-2012秋(7页珍藏版)》请在金锄头文库上搜索。

1、实验 5、函数1 程序填空给定程序中函数 fun 的功能是:找出 100n(不大于 1000)之间的三位数字相等的所有整数,把这些整数放在 s 所指的数组中,整数的个数作为函数值返回。在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果即可。程序填空如下:#include #define N 100int fun(int *s,int n) int i,j,k,a,b,c;j=0;for(i=100;i1000);num=fun(a,n);printf(“nnThe result:n”);for(i=0; iunsigned long fun(unsigned long n) u

2、nsigned long x=0,s,i; int t;s=n;/*found*i=0;/*found*while(s99999999|nunsigned long fun(unsigned long n) unsigned long x=0,s,i; int t;s=n;/*found*/i=1;/*found*/while(s0) t=s%10;if(t%2=0)/*found*/x=x+t*i; i=i*10;s=s/10;return x;main() unsigned long n=1;while(n99999999|n#include #define M 5int fun(int

3、n,int xxMM)main()int aaMM = 1,2,3,4,5,4,3,2,1,0,6,7,8,9,0,9,8,7,6,5,3,4,5,6,7;printf(“nThe sum of all elements on 2 diagnals is %d.“,fun(M,aa);参考程序如下:#include #include #define M 5int fun(int n,int xxMM) int i,j,sum=0;for(i=0;i1)从上述公式可以看出:斐波那契数列的第 1 个数是 0,第 2 个数是 1,从第 3 个数开始,以后每个数都是前两个数之和。解:方法一:用递归法实

4、现#include int Fib(int n);main() int i;for (i=0;ivoid main() fib(30); fib(int n) long int f100;int i;f0=0;f1=1;for(i=2;i1000, and multiple): 15001500 is not multiple of 1000.Please input your money(1000, and multiple): 10000Please input everyday net value in this week:0.9872 0.9935 1.0102 0.9905 1.02

5、35Quotient Net Value Increase Rate Current Value Current Payoff9850 0.9872 0.00% 9724 -3259850 0.9935 0.64% 9786 -2639850 1.0102 1.68% 9950 -999850 0.9905 -1.95% 9756 -2929850 1.0235 3.33% 10081 31Average Net Value in this week = 1.00098方法、用一维数组实现:#include void main() int money,i,quotient/*基金份额*/,cu

6、rrent_value5/*用户当前净值*/,current_payoff5/*浮动盈亏*/; float net_value5/*当日每份基金净值*/,increase_rate5/*每日净值增长率*/,sum=0; printf(Please input your money(=1000, and multiple):); scanf(%d, while(money=1000, and multiple):); scanf(%d, printf(please input everyday net value in this week:n); for(i=0;i#include genlib

7、.h#include simpio.h#include strlib.h#define PREVALUE 1 /成立时每份面值#define PURCHASERATE 0.015 /申购费率#define REDEMPTIONRATE 0.005 /赎回费率#define DAY 5 /工作日void main(void)int amount,i;double dateDAY5;double sum=0.0;printf(Please input your money(=1000, and multiple): );amount=GetInteger();while(amount=1000,

8、and multiple): );amount=GetInteger();printf(Please input everyday net value in this week: );for(i=0;i5;i+) datei0=amount*(1-PURCHASERATE)/PREVALUE; /Quotient-基金份额datei1=GetReal(); /Net value-当日每份基金净值datei3=datei0*datei1; /Current Value-用户当前净值datei4=datei3*(1-REDEMPTIONRATE)-amount; /Current Payoff-浮

9、动盈亏if(datei40)datei4=datei4-0.5; /当 Current Payoff 为负时-0.5 以便四舍五入elsedatei4=datei4+0.5; /当 Current Payoff 为正时+0.5 以便四舍五入sum=sum+datei1;date02=-1.28; /由于上周最后一个交易的当日每份基金净值未知,所以第一日的每日净值增长率由程序定义for(i=1;i=4;i+) datei2=(datei1-datei-11)/datei-11*100; /Increase Rate-每日净值增长率printf(Quotient Net Value Increase Rate Current Value Current Payoff);for(i=0;i=4;i+) printf(%8d,(int)datei0);printf(%11.4f,datei1);printf(%14.2f%,datei2);printf(%15d,(int)(datei3+0.5); /为了四舍五入到整数所以+0.5printf(%16dn,(int)datei4);printf(Average Net Value in this week = %.5fn,sum/DAY);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号