C++程序设计题库(182道含答案)(10)

2019-09-01 15:20

【程序设计】

--------------------------------------------------

题目:给定一组十进制正整数,请统计各个正整数的各位 数字中0的个数。数据保存在f1.txt文件中,要求编写 计算0的个数的函数countZero。

--------------------------------------------------

注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在注释形式标识Program和 End之间填入所编写的若干语句。

------------------------------------------------*/

#include #include

using namespace std;

int countZero(int num) {

int digi, count = 0;

/**********Program**********/

/********** End **********/ }

int main() {

int num, count = 0;

ifstream input;

input.open(\ ofstream output;

output.open(\

while(!input.eof())

{

input >> num;

output << countZero(num); count++; if(count == 40) {

count = 0; output << endl; } else

output << \ }

input.close(); output.close();

cout <<\ cin.ignore(cin.rdbuf()->in_avail() + 1);

return 0; }

答案:if(num == 0) return 1; while(num != 0)

第33题 (10.0分) 题号:591

/*------------------------------------------------ 【程序设计】

--------------------------------------------------

题目: 用“辗转相除方法”计算两个数 x,y 的最大公约 数

-------------------------------------------------- 注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。

{ }

return count;

digi = num % 10; if(0 == digi)

count += 1;

num = (num - digi) / 10;

------------------------------------------------*/

#include #include using namespace std;

#include

void writeinfile(int n);

void main() {

int x,y,n; x=25,y=10;

/**********Program**********/

/********** End **********/ cout<

void writeinfile(int n) {

fstream myfile;

myfile.open(\myfile<

答案:---------------------- n=x%y; while(n!=0) {x=y;y=n;n=x%y;} ----------------------

第34题 (10.0分) 题号:617

/*------------------------------------------------ 【程序设计】

--------------------------------------------------

题目:请编写函数

int occ_num(int a[], int x, int len)

计算整数 x 在数组 a 中出现的次数,其中 len 为数组a的长度。

--------------------------------------------------

注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在函数的花括号中介于 \ 和

\ 的部分填入所编写的若干语句。

------------------------------------------------*/

#include #include using namespace std;

#define N 20

int occ_num(int a[], int x, int len) {

/**********Program**********/

/********** End **********/ }

int main() {

ifstream inf(\ ofstream ouf(\ int a[N];

for(int i=0;i>a[i];

ouf<< occ_num(a,a[1],N)<

答案:

---------------------- int m =0;

for(int i=0;i

----------------------

第35题 (10.0分) 题号:598

/*------------------------------------------------ 【程序设计】

--------------------------------------------------

题目: 编写函数 reverse, 对给定的10个数置逆序排列.

-------------------------------------------------- 注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。

------------------------------------------------*/

#include #include using namespace std;

#define N 10

void reverse(int a[], int len) // a 是待操作的数组,len 是数组中元素的数目 {

int i, t;

/**********Program**********/

/********** End **********/ }

int main() {


C++程序设计题库(182道含答案)(10).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:五年级解决问题练习题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: