11、打印输出以下图形(图中每两个“*”之间有一个空格)。 * * * *
* * * * *
* * * * * * *
* * * * * * * * * 源文件:
#include
{ 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
/*************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
{ 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
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
{ 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
{ 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
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
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(\}