首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
已知数据文件in.dat中存放有300个四位数,并已调用读函数readDat()把这些数存入数组a中,请编写函数jsValue(),其功能是:求出千位数上的数加个位数上的数等于百位数上的数加十位数上的数的个数cnt,再把所有满足此条件的四位数依次存入数组b
已知数据文件in.dat中存放有300个四位数,并已调用读函数readDat()把这些数存入数组a中,请编写函数jsValue(),其功能是:求出千位数上的数加个位数上的数等于百位数上的数加十位数上的数的个数cnt,再把所有满足此条件的四位数依次存入数组b
admin
2013-12-06
18
问题
已知数据文件in.dat中存放有300个四位数,并已调用读函数readDat()把这些数存入数组a中,请编写函数jsValue(),其功能是:求出千位数上的数加个位数上的数等于百位数上的数加十位数上的数的个数cnt,再把所有满足此条件的四位数依次存入数组b中,然后对数组b巾的四位数按从小到大的顺序进行排序。最后通过main()函数调用写函数writeDat(),把数组b中的数输出到文件out.dat中。
例如:6712,6+2=7+1,则该数满足条件,
存入数组b中。且个数cnt=cnt+1。
8129,8+9 1=1+2.则该数不满足条件,忽略。
【试题程序】
#inelude
int alS00],b[300],cnt=0;
void writeDat();
void readDat();
void isValue()
{
}
main()
{
int i;
readDat();
jsValue();
writeDat();
printf(“cnt=%d\n”,cnt);
for(i=0;i
printf(”b[%d]=%d\n”,i.b
);
}
void readDat()
{
FILE*fP;
int i;
fp=fopen(“in.dat”,“r”);
for(i=0;i<300Ii++)
fscanf(fp,“%d。”,&a
);
fclose(fp);
}
void writeDat()
{
FILE*fp;
int i;
fp=fopen(“out.dat”,“W”);
fprintf(fp,“%d\n”,cnt);
for(i=0;i
fprintf(fp,“%d\n”.b
);
fclose(fp);
}
选项
答案
void jsValue() { int i,j; /*定义变量*/ int a1,a2,a3,a4; int temp; for(i=0;i<300;i++) {al=aEi-]%10, /*数位分解*/ a2=aEi]%100/10; a3=a[i]%1000/100; a4=a[i]/1000; if(a4+a1==a3+a2) /*判断条件*/ blent++]=a[i]; } for(i=0;i
b[j]) { temp=b[j], bEi]=b[j]; b[j]=temp; } }
解析
转载请注明原文地址:https://kaotiyun.com/show/0olZ777K
本试题收录于:
三级数据库技术题库NCRE全国计算机三级分类
0
三级数据库技术
NCRE全国计算机三级
相关试题推荐
按行优先顺序存储下三角矩阵的非零元素,则计算非零元素aij(1≤j≤i≤n)的地址的公式为
对一个由n个关键码组成的序列,借助排序过程选出其中最大的关键码,要求关键码比较次数和移动次数最少,应当使用下列哪种排序方法?
一个简单的方法是采用【】来指示磁盘存储空间的使用情况。
Oracle针对Internet/Intranet的产品是
当关系模式R(A,B)已属于3NF,下列说法中哪一个是正确的?
下面所列的条目中Ⅰ.语法检查Ⅱ.语义检查Ⅲ.用户存取权限检查Ⅳ.数据完整性检查当用户发出查询数据库数据的命令时,数据库管理系统需要进行的检查是
如果允许不同用户的文件可以具有相同的文件名,通常采用哪种形式来保证按名存取的安全?
发生中断时被打断程序暂停点称为【】。
数据库设计的概念结构设计阶段,表示概念结构的常用方法和描述工具是
设X→Y是一个函数依赖,且对于任何X’∈X,X’→Y都不成立,则称X→Y是—个
随机试题
预测某企业未来收益,其中前5年分别为120万元、125万元、128万元、120万元和130万元,从第6年开始,企业收益将基本保持在120万元的水平上,已知折现率、资本化率同为10%。求该企业的整体资产评估值。
下述哪一项与系统性红斑狼疮诊断有关
我方以CFR贸易术语与B国的H公司订立成交一批消毒碗柜的出口合同,合同规定装运时间为4月15日前。我方备妥货物,并于4月8日中午装船完毕,由于遇星期日休息,我方的业务员未及时向买方发出装运通知,导致买方未能及时办理投保手续,而货物在4月8日晚因发生了火灾被
Therequirementsforhighschoolgraduationhavejustchangedinmycommunity.Asaresult,allstudentsmust【C1】______sixtyhou
WhohastherealpowerintheBritishgovernment?
通报适用于()。
串的长度是
果
Howmanypeopleliveincitiesnow?
They______afootballmatchatfouro’clockyesterdayafternoon.
最新回复
(
0
)