a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 46|回复: 0

[数据库] 2011年计算机等级三级数据库上机题及答案(6)

[复制链接]
发表于 2012-7-31 21:12:12 | 显示全部楼层 |阅读模式
 16.下列程序的功能是:寻找并输出11~999之间的数m,它满足m、m2和m3均为回文数。所谓回文数是指各位数字左右对称的整数,例如121、676、94249等。满足上述条件的数如m=11,m2=121,m3=1331皆为回文数。请编写函数int palindromevalue(long n)实现功能:如果是回文数,则函数返回1,反之则返回0。最后,把结果输出到文件OUT.dat中。  【答案】$ v4 W9 _$ ^9 z; @( y0 o" E: G
  int palindromevalue(long n)
# @, Y- i4 ?. \: L) w' Z& v0 B0 ~& A  { int i, strl, half;8 z5 |0 x4 a" ?( l
  char temp[20];
" [# K; i2 S# l. d0 U  ltoa(n, temp, 10);
+ Q% ~" d2 I# `; z$ x# z3 A  strl = strlen(temp);
* _* k4 x; I& t+ O4 c' B5 w+ A  half = strl/2;
( @* A% ~$ w9 `/ L/ T  for (i=0; i= half)0 Q% q+ D& \/ A6 c9 J
  return 1;& [" A) o; M$ v$ @
  else
0 U5 Y+ [9 d- H/ z5 D4 l( @  return 0;
- M- b4 x  j% R$ f% K/ l/ @  n  }
) t; J4 |4 u! g$ w' n  17请补充程序,使得程序能实现以下功能:6 Q  {  ^" [5 i$ h
  从文件IN.dat中读取200个整数至数组number中,求出奇数的个数cnt1和偶数的个数cnt2以及数组number下标为偶数的元素值的算术平均值ave(保留2位小数)。把结果cnt1、cnt2、ave输出到OUT.dat中。( n2 K- e' o3 q8 }# l
  【答案】
, B! P7 S  k+ _  for (i=0, j=0, cnt1=0, cnt2=0; i>= 4;2 v& F/ p9 a. I9 c7 M9 ^
  string[j] += string[j-1];
; ]' I3 E  }' S6 H- w0 I  }
  }0 K2 w  b0 m/ [3 i  string[0] += ch;# h3 U( g: C! {' p+ c3 i
  }
6 G- p) f% j, f* N6 A. T$ Z  }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-19 00:23 , Processed in 0.322433 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表