河南科技大学c语言题库(5)

2019-03-05 21:35

11、打印输出以下图形(图中每两个“*”之间有一个空格)。 * * * *

* * * * *

* * * * * * *

* * * * * * * * * 源文件:

#include #include #include #include main()

{ int i,j,k;

/************found************/ for(i=1;i<=5;i++) {

for(j=1;j<=10-2*i;j++) printf(\

for(j=1;j<=2*i-1;j++) printf(\

/************found************/ printf(\} }

12、求 ∑n!(n=20)(即求:1!+2!+3!+ ?? + 20!) 源文件:

#include #include #include #include main()

/*************found**************/ float s,t; int n; s=0;t=1;

/*************found**************/ for(n=0;n<20;n++) { t=t*(n+1); s=s+t; }

printf(\\\n\}

13、输入一个百分制成绩,打印出五级记分成绩。考试成绩在90分或90分以上为优秀,80~89分为良好,70~79为中等,60~69为及格,低于60分为不及格。

源文件:

#include #include #include #include main()

{ int score,t;

printf(\do

scanf(\

while(score<0||score>100); t=score/10;

/*************found**************/ switch(t) { case 10:

case 9:printf(\case 8:printf(\case 7:printf(\case 6:printf(\/*************found**************/ default :printf(\} }

14、求一维数组a中的最大元素及其下标。例如,当一维数组a中的元素为:34,4,2,7,3,12,5,8,5,9,程序的输出应为:The max is: 34,pos is: 0 。 源文件:

#include #include int max;

maxarr(int arr[ ]) { int pos,i;

/************found************/ max = arr[0]; pos = 0;

for ( i=1; i<10; i++)

/************found************/ if (max < arr[i]) {

max = arr[i]; pos = i;

}

return (pos); }

main()

{ int a[10]={34,4,2,7,3,12,5,8,5,9};

printf(\}

15、求二维数组a中的最大值和最小值。 例如,当二维数组a中的元素为: 4 4 34 37 3 12 5 6 5

程序的输出应为:The max is: 37 The min is: 3 。 源文件:

#include #include main()

{ int a[3][3]={4,4,34,37,3,12,5,6,5},i,j,max,min;

max = min = a[0][0]; for ( i=0; i<3; i++)

/************found************/ for ( j=0; j<3; j++) { if ( max < a[i][j] ) max = a[i][j];

/************found************/ if (min > a[i][j]) min = a[i][j]; }

printf(\printf(\}

16、求一维数组a中值为奇数的元素之和。

例如,当一维数组a中的元素为:11,4,2,7,3,12,5,34,5,9 程序的输出应为:The result is: 40。 源文件:

#include #include main()

{ int arr[10]={11,4,2,7,3,12,5,34,5,9},i;

/************found************/ int s=0;

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

/************found************/ if (arr[i] % 2 == 1) s = s + arr[i];

printf(\}

17、将[m,n]之间的所有素数存放到一维数组a中,并输出这些素数。 例如,如果m=2,n=20,程序的输出应为: 2 3 5 7 11 13 17 19 源文件:

#include #include #include prime (int m) { int j,k; k=sqrt(m);

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

if (m % j == 0) return (0); return (1); }

main()

{ int a[100],i,c=0,m,n; printf(\scanf(\

/************found************/ for (i=m; i<=n; i++)

/************found************/ if(prime(i)==1) { a[c]=i;

printf(\++c; } }

18、求一维数组a中所有元素的平均值。

例如,当二维数组a中的元素为:10,4,2,7,3,12,5,34,5,9,6,8 , 程序的输出应为:The everage is: 8.75 。 源文件:

#include #include

float average(int a[],int n) /************found************/ {

int j; float aver;

/************found************/ float s=0;

for ( j=0; j

main()

{ int a[12]={10,4,2,7,3,12,5,34,5,9,6,8}; printf(\}


河南科技大学c语言题库(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《小学语文课堂有效性教学的研究》开题报告

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

马上注册会员

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