三、写出程序运行结果
1. #include<stdio.h>
void main() {
int i,j,k=0;
for(i=0; i<5; i++)
for(j=i; j<5; j++) k++;;
printf("%d/n",k);
}
结果:15
2. #include<stdio.h>
void main() {
int x=20;
int i=2;
while(i<x) {
if(x%i==0) {printf("%d ",i); x/=i;}
i++;
}
}
结果:25
3. #include<stdio.h>
void main() {
int a[8]={76,63,54,95,40,75,90,66};
int i, s=0;
for(i=0; i<8; i++)
if(a[i]>=70 && a[i]<=90) s+=a[i];
printf("s=%d/n",s);
}
结果:241
4. #include<stdio.h>
int WF(int x, int y) {
x=x+y;
y+=x;
return x+y;
}
void main() {
int x=3, y=8;
printf("%d/n",WF(x,y));
}
结果:30
5. #include<stdio.h>
void main()
{
int x=5;
switch(2*x-1) {
case 4: printf("%d ",x); break;
case 7: printf("%d ",2*x); break;
case 10: printf("%d ",3*x); break;
default: printf("%s ","default");
}
printf("%s/n","switch end.");
}
结果:default switch end.
6. #include<stdio.h>
void main() {
int f1,f2,i;
f1=1;
printf("%d ",f1);
for(i=2;i<=5;i++) {
f2=3*f1+1;
printf("%d ",f2);
f1=f2;
}
printf("/n");
}
结果:1 4 13 40 121
7. #include<stdio.h>
void main() {
int a[10]={12,39,26,41,55,63,72,40,83,95};
int i, i1=0, i2=0;
for(i=0;i<10;i++)
if(a[i]%2==1) i1++; else i2++;
printf("%d %d/n",i1,i2);
}
结果:6 4
8. #include<stdio.h>
#include<string.h>
void main( ) {
char s[15]="567891234";
int i, n=strlen(s) ;
for(i=0; i<n/2; i++) {
char c=s[i];
s[i]=s[n-1-i];
s[n-1-i]=c;
}
printf("%s/n",s);
}
结果:432198765
9. #include<stdio.h>
int LB(int *a, int n) {
int i,s=1;
for(i=0;i<n;i++) s*=*a++;
return s;
}
void main() {
int a[]={1,2,3,4,2,4,5,2};
int b=LB(a,4)+LB(a+3,3);
printf("b=%d/n",b);
}
结果:b=56
10. #include<stdio.h>
void main() {
int i,s=0;
for(i=1;i<6;i++) s+=i*i;
printf(“s=%d/n”,s);
}
结果:s=55
11. #include<stdio.h>
#define N 6
void main()
{
int i,a[N]={2,5,8,10,15,21};
for(i=0; i<N; i++)
if(a[i]%5) printf("%d ",a[i]);
printf("/n");
}
结果:2 8 21
12. #include<stdio.h>
#include<string.h>
void main() {
int i;
unsigned int len;
char* a[5]={"student","worker","cadre","soldier","zzeasan123"};
len=strlen(a[0]);
for(i=1; i<5; i++)
if(strlen(a[i])>len) len=strlen(a[i]);
printf("%d/n",len);
}
结果:10
13. #include<stdio.h>
void main()
{
int a,b;
for(a=2,b=3; b<20;) {
printf("%d %d ",a,b);
a=a+b;
b=a+b;
}
printf("%d %d/n",a,b);
}
结果:2 3 5 8 13 21
14. #include<stdio.h>
void LE(int* a, int* b) {
int x=*a;
*a=*b; *b=x;
}
void main() {
int x=15, y=26;
printf("%d %d/n",x,y);
LE(&x,&y);
printf("%d %d/n",x,y);
}
结果:15 26
26 15
15. #include<stdio.h>
void main() {
int i, s=0;
for(i=1;;i++) {
if(s>30) break;
if(i%2==0) s+=i;
}
printf("s=%d/n",s);
}
结果:s=42
16. #include<stdio.h>
void main() {
int a[9]={36,25,48,24,55,40,18,66,20};
int i, b1, b2;
b1=b2=a[0];
for(i=1; i<9; i++) {
if(a[i]>b1) b1=a[i];
if(a[i]<b2) b2=a[i];
}
printf("%d %d/n",b1,b2);
}
结果:66 18
17. #include<stdio.h>
void SB(char ch) {
switch(ch) {
case 'A': case 'a':
printf("WW "); break;
case 'B': case 'b':
printf("GG "); break;
default:
printf("BB "); break;
}
}
void main() {
char a1='a',a2='B',a3='f';
SB(a1);SB(a2);SB(a3);
printf("/n");
}
结果: WW GG BB
18. #include<stdio.h>
#define M 6
void main()
{
int i,x;
int a[M]={10,15,22,37,46,58};
for(i=0; i<M/2; i++) {x=a[i]; a[i]=a[M-1-i]; a[M-1-i]=x;}
for(i=0; i<6; i++) printf("%d ",a[i]);
printf("/n");
}
结果:58 46 37 22 15 10
19. #include<stdio.h>
struct Worker {
char name[15]; int age; float pay;
};
void main() {
struct Worker x={"wanghua",52,2350};
struct Worker y, *p;
y=x; p=&x;
printf("%d %7.2f/n", y.age+p->age, p->pay+20);
}
结果:104 2370.00
20. #include<stdio.h>
void main()
{
int x=60;
int i=2, p=1;
while(1) {
if(x%i==0) {p*=i; x/=i;}
if(i<x) i++; else break;
}
printf("%d/n",p);
}
结果:30
21. #include<stdio.h>
void main() {
int a[8]={76,63,54,62,40,75,90,58};
int i;
for(i=0; i<8; i++)
if(a[i]>70) printf("%d ",a[i]);
printf("/n");
}
结果:76 75 90
22. #include<stdio.h>
void WF(int x, int y) {
x=x+y;
y+=x;
printf("%d %d/n",x,y);
}
void main() {
int x=3, y=8;
WF(x,y);
}
结果:11 19
23. #include<stdio.h>
int LA(int *a, int n) {
int i,s=0;
for(i=0;i<n;i++) s+=a[i];
return s;
}
void main() {
int a[5]={3,4,6,10,20};
int b=LA(a,5);
int c=LA(a+2,3);
printf("%d %d/n",b,c);
}
结果:43 36
24. # tnclude<stdlO h>
VOId mam() {
int i, s=O,
for(i= 1 , i< 10 ,i+ = 2) s+ =i,
pnntf( “s=%d/n" , s),
}
输出结果: s=25
25. # mclude<stdlO h>
canst tnt M=20,
VOId mam() {
int i=2, k=O,
whlle(i<M) {
If (M%i==O) k++,
1 ++,
prnt£<K=%d/n",k) ,
输出结果: k=4
26. # include<stdiO h>
int a[6] = {4 ,5, 6, 15, 20, 12},
VOid matn()
int i, s1 , s2 ,
sl=s2=O,
for(i=O , i<6, i++)
if( a[ I] %3) sl+=a[i] , else s2 十= a[i] ,
prlntf ("%d%d/n ,sl , s2) ,
输出结果: 29 33
27.# include<stdlO h>
VOld matn() {
int a[3][3] = {{3 ,5 ,7} , {9 , 11 , 13} ,{6, 8, 2 0 } },
int i, k=O. *p= &a[O][O] ,
for(i=O ,i< 9 ,i+ +)
If( *p++<=8) k++,
prlntf( k=%d/n" ,k) ,
输出结果: k=5
28. #ic1ude<stdiO h>
# mc1ude<stnng h>
struct Worker {char name[l5] , int age, float pay, } ,
VOId mam() {
struct Worker x ,
char *t= “lioutmg “,
int d=38 , float f=400 ,
strcpy(x name,t) ,
x age=d,x pay=f,
x age--,x pay/=2 ,
prnt£("%s%d%62f/n",x name,x age,x pay) ,
输出结果: houtmg 37 200 00
29. # include<stdio. h>
void mainO {
int n=6 , y=l;
while(n--) y +=3;
printf( "y= %d/n" ,y) ;
输出结果: y=19
30. # include<stdio. h>
void main()
int i,s=O;
for (i= 1; i<8;i++)
if<i%2= =0 II i%3= =0) s +=i;
print£(“ s=%d/n”, s) ;
输出结果: s=15
31. #include<stdio. h>
void main(){
char a[] = “abcdbfkgamd”;
int il=O. i2=0, i=O;
while(a[i]) {
if(a [i]<”e”il++; else i2++;
i++ ;
print£(" %d %d/n" , il ,i2) ;
输出结果: 7 4
32. #include<stdio. h>
VOId main() {
int a[8]={4 ,8 ,12,16,20,24,28,32};
int * p=a;
do {
printf("%d ",*p ) ;
p+=3;
} whi1e(p<a 十8) ;
print£( "/n”t) ;
输出结果: 4 16 28
33. #include<stdio. H>
struct Worker { char name[15J; int age; double pay;};
void mainO {
struct Worker a[4J = {{" abc" , 20 ,2420} , {" defa" ,50 ,3638} ,
{" ghin" , 40 ,2560} , {"jklt" ,36 ,2375}} ;
inti , s=O;
for(i=O; i<4; i ++ ) s +=a[i]. age;
printf("s=% 5. 2Lf/n" , ( double)s/4) ;
输出结果: s=36.50
来源:网络整理 免责声明:本文仅限学习分享,如产生版权问题,请联系我们及时删除。
相关文章:
电大《商务谈判实务》平时作业(四)04-27
商务英语(上)期末复习资料04-27
电大《商务谈判实务》平时作业(三)04-27
电大《商务谈判实务》平时作业(二)04-27
电大《地域文化》电大《黑龙江经济文化》半开卷试题404-27
电大《企业集团财务管理》复习资料04-27
下列关于法人分类的表述中,错误的是()。A以法人的成立04-27
红旗中学为了迎接建校50周年庆典,特委托某工艺美术院设04-27