1. 阅读程序并填空。该程序的功能是:
通过公式:
???6?1?111,求?的近似值。 ????2?23?3n?n#include
double pi(long n) { double s=1.0; long i;
for( ① ;i<=n;i++) ①
s=s+ ② ; ②
③ (sqrt(6*s)); ③ }
main()
{ printf(\
2. 阅读程序并填空。该程序的功能是:将二维数组a行和列元素互换后存入到另一个二维数组b中。
#include
{ int a[2][3]={{1,2,3},{4,5,6}}; int b[3][2],i,; for(i=0;i<2;i++)
for(j=0; ① ;j++) ① ② ; ② for(i=0; ③ ;i++) ③ { for(j=0;j<2;j++)
printf(\ printf(\ } }
3. 写出程序的运行结果。
#include
int a[3][3]={1,2,3,4,5,6,7,8,9}; for(i=0;i<3;i++) for(j=i;j<3;j++)
printf(\ printf(\
输出结果为: 4. 写出程序的运行结果。
#include
{ int a[3][3]={{1,2},{3,4},{5,6}}; int i,j,s=0; for(i=1;i<3;i++) for(j=0;j
printf(\
输出结果为:
21
5. 写出程序的运行结果。
#include
{ int s=0,n;
for(n=0;n<3;n++) { switch(s) { case 0:
case 1:s+=1;
case 2:s+=2;break; case 3:s+=3; default:s+=4; }
printf(\ } }
输出结果为: 6. 写出程序的运行结果。
#include
{ int x,y;
for(y=1,x=1;y<=50;y++) { if(x>=10) break; if(x%2==1) { x+=5; continue; } x-=3; }
printf(\ }
输出结果为:
7. 编写函数void CountFun(char *ps),该函数的功能是:查找并输出指针ps字符串中英文字母(包括
大小写)的次数。
void CountFun(char *ps) { int i,cnt=0;
}
22
main()
{ char str[60]; scanf(\ CountFun(str); }
8. 编写函数int Isprime(int x),该函数的功能是:判断正整数x是否素数(即只能被1和它本身整除
的数),若是素数函数返回1(真), 否则返回0(假)。 int Isprime(int x) { int i;
}
main()
{ int number;
printf(\请输入正整数number(>=2):%d\ if(Isprime(number))
printf(\else
printf(\
9. 编写函数void Change(char *ps),该函数的功能是:将指针ps所指字符串中小写英文字母转换为下
一个小写英文字母。
(例如:a→b,b→c,c→d,??,y→z,z→a,??)。 void Change(char *ps) { int i;
main()
{ char str[60]; scanf(\ Change(str); }
23
}
10. 编写函数void Change(int array[N]),将数组array中的前N个元素倒序存放。
#define N 10
void Change(int array[N])
{ int i,j,temp;
}
11. 编写函数void CountFun(char str[]),该函数的功能是:查找并输出字符串str
中数字字符的次数。
void CountFun(char str[]) { int i,cnt=0;
}
24
相关推荐: