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

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

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

编程题:

20.编写函数int fun(int lim,int aa[MAX]),该函数的功能是求出小于或等于lim的所有素数并放在aa数组中,该函数返回所求出的素数的个数。

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

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

#include <stdio.h>

#include <conio.h>

#define MAX 100

 

int fun( int lim, int aa[MAX])

{

}

 

main()

{

int limit,i,sum;

int aa[MAX] ;

clrscr() ;

printf(“输入一个整数”);

scanf(” %d”, &limit);

sum=fun(limit, aa);

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

{

if(i%10 == 0 && i !=0)

printf(“n”);

printf(“%5d”, aa[i]);

}

}

 

22.N名学生的成绩已在主函数中放入一个带头节点的链表结构中,h指向链表的头节点。请编写函数fun,它的功能是:找出学生的最高分,由函数值返回。

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

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

#include <stdio.h>

#include <stdlib.h>

#define  N  8

 

struct  slist

{

double  s;

struct slist *next;

};

 

typedef  struct slist  STREC;

 

double  fun( STREC *h )

{

}

 

STREC *creat( double *s)

{

STREC *h,*p,*q;

int  i=0;

h=p=(STREC*)malloc(sizeof(STREC));

p->s=0;

while(i<N)

{

q=(STREC*)malloc(sizeof(STREC));

q->s=s[i];

i++;

p->next=q;

p=q;

}

p->next=0;

return  h;

}

 

outlist(STREC *h)

{

STREC  *p;

p=h->next;

printf(“head”);

do

{

printf(“->%2.0f”,p->s);

p=p->next;

}

while(p!=0);

printf(“nn”);

}

 

main()

{

double  s[N]={85,76,69,85,91,72,64,87}, max;

STREC  *h;

h=creat(s);

outlist(h);

max=fun(h);

printf(“max=%6.1fn”,max);

}

 

改错题:

76.下列给定程序中函数fun的功能是:将长整型数中每一位上为偶数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。例如,当s中的数为87653142时,t中的数为8642。

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

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

试题程序:

#include <conio.h>

#include <stdio.h>

 

void fun(long s,long *t)

{

int d;

long s1=1;

*t=0;

while(s>0)

{

d=s%10;

if (d%2==0)

{

*t=d* s1+*t;

s1*=10;

}

s =10;

}

}

main()

{

long  s, t;

clrscr();

printf(“nPlease enter s:”);

scanf(“%ld”, &s);

fun(s, &t);

printf(“The result is :%ldn”, t);

}

 

 

78.下列给定程序中函数fun的功能是:判断一个整数m是否是素数,若是返回1,否

则返回0。在main()函数中,若fun返回1则输出YES,若fun返回0则输出NO!。

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

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

试题程序:

#include <conio.h>

#include <stdio.h>

 

int fun(int m)

{

int k=2;

while(k<=m&&(m%k))

k++

if(m=k)

return 1;

else

return 0;

}

 

main( )

{

int n;

clrscr( );

printf( “nPlease enter n:” );

scanf( “%d”,&n );

if( fun ( n ) )

printf( “YESn” );

else

printf(“NO!n”);

}

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

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

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