栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

C语言编程笔试题(第一套)

C语言编程笔试题(第一套)

1.m个人的成绩存放在score数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。

例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人数应该是4,below中的数据应为10、20、30、40。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <conio.h>

#include <stdio.h>

#include <string.h>

 

int fun(int score[],int m, int below[])

{

 

}

main()

{

int i,n,below[9];

int score[9]={10,20,30,40,50,60,70,80,90};

clrscr();

n=fun(score,9,below);

printf(“nBelow the average score are :”);

for(i=0;i<n;i++)

printf(“%d “,below[i]);

}

 

8.编写函数fun,函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。

S=1+1/(1+2)+1/(1+2+3)+……1/(1+2+3+…+n)

例如:若n的值为11时,函数的值为1.833333。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include<conio.h>

#include<stdio.h>

#include<string.h>

 

float fun (int n)

{

}

main()

{

int n;

float s;

clrscr();

printf(“nPlease enter N:”);

scanf(“%d”,&n);

s=fun(n);

printf(“The result is: %fn”,s);

}

 

改错题:

1.下列给定程序的功能是:读入一个整数k(2≤k≤10000),打印它的所有质因子(即所有为素数的因子)。例如,若输入整数2310,则应输出:2、3、5、7、11。

请改正程序中的错误,使程序能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include     “conio.h”

#include     “stdio.h”

IsPrime    ( int n    ) ;

{

int i, m;

m=1;

for(i=2;i<n;i++)

if !(n%i)

{

m=0;

break;

}

return(m);

}

 

main()

{

int j, k;

clrscr();

printf(“nplease enter an integer number between 2 and 10000:”);

scanf(“%d”,&k);

printf(“nnThe   prime factor(s)   of %d is(are):”,k);

for(j=2;j<k;j++)

if((!(k%j))&&(IsPrime(j)))

printf(” %4d,”,j);

printf(“n”);

}

 

 

6.下列给定程序中,函数fun的功能是:根据整型形参m的值,计算如下公式的值。

1     1       1

T=1- ―  – -  -… -

2×2   3×3     mxm

例如,若m中的值为5,则应输出:0.536389。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <conio.h>

#include <stdio.h>

double fun(int m)

{

double y=1.0;

int i;

for(i=2;i<m;i++)

y-=1/(i*i);

return(y);

}

main()

{

int n=5;

clrscr();

printf(“nThe result is %1fn”,fun(n));

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265377.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号