1、#include#include void main()void main()int a5050,i,j,k,n;int a5050,i,j,k,n;scanf(%d,&n);scanf(%d,&n);for(k=1;k=n;k+)for(k=1;k=n;k+)for(i=k;i=2for(i=k;i=2*n-k;i+)n-k;i+)for(j=k;j=2for(j=k;j=2*n-k;j+)n-k;j+)aij=k;aij=k;for(i=1;i=2for(i=1;i=2*n-1;i+)n-1;i+)for(j=1;j=2for(j=1;j=2*n-1;j+)n-1;j+)printf(%3
2、d,aij);printf(%3d,aij);printf(n);printf(n);16.读程序并填空。下面程序的功能是:将字符数组读程序并填空。下面程序的功能是:将字符数组a中下标值为中下标值为偶数的元素从小到大排列,其他元素不变,最后输出数组偶数的元素从小到大排列,其他元素不变,最后输出数组a。#include#include#include#include void main()void main()char a=clanguage,t;char a=clanguage,t;int i,j,k;int i,j,k;k=k=;for(i=0;i=k-2;i+=2)for(i=0;i=k-
3、2;i+=2)for(j=for(j=;jk;jajaiajcouta;couta;strlen(a)strlen(a)#include#include void main()void main()char s=012xy;char s=012xy;int i,n=0;int i,n=0;for(i=0;si!=0;i+)for(i=0;si!=0;i+)if(si=a&si=a&si=z)n+;n+;coutnendl;coutnendl;17.写出下列程序运行结果。写出下列程序运行结果。2012xy0s012345 18.写出下列程序运行结果。写出下列程序运行结果。6565ab20ch01
4、2345#include#include void main()void main()char ch=65ab23;char ch=65ab23;int i,s=0;int i,s=0;for(i=0;chi=0&chi=0&chi=9;i+)s=10s=10*s+chi-0;s+chi-0;coutsendl;coutsendl;36#include#include void main()void main()char a50,b50;char a50,b50;int i;int i;gets(a);gets(a);gets(b);gets(b);i=0;i=0;while(ai=bi)&(
5、ai!=0)&(bi!=0)while(ai=bi)&(ai!=0)&(bi!=0)i+;i+;if(aibi)if(aibi)printf(ab);printf(abi)else if(aibi)printf(ab);printf(ab);elseelseprintf(a=b);printf(a=b);比较两个字符串大小:比较两个字符串大小:#include int jie(int x)int i,res=1;for(i=1;i=x;i+)res*=i;return res;void main()int sum;sum=jie(1)+jie(1)+jie(2)+jie(3)+jie(5)+j
6、ie(8);coutsumn;a1=1;a2=1;for(i=3;i=n;i+)ai=ai-1+ai-2;sum=0;for(i=1;i=n;i+)sum+=jie(ai);coutsumendl;#include void fun(int a,int b,int c)c=a*b;void main()int c=1;fun(2,3,c);printf(%dn,c);20.写结果。写结果。1c 1形参形参abc#include#include int prime(int n)int prime(int n)int i,leap=1;int i,leap=1;for(i=2;i=n-1;i+)f
7、or(i=2;i=n-1;i+)if(n%i=0)if(n%i=0)leap=0;leap=0;return leap;return leap;void main()void main()int i,n;int i,n;for(n=4;n=50;n+=2)for(n=4;n=50;n+=2)for(i=2;in;i+)for(i=2;in;i+)if(prime(i)&prime(n-i)if(prime(i)&prime(n-i)printf(%d=%d+%dn,n,i,n-i);printf(%d=%d+%dn,n,i,n-i);break;break;验证哥德巴赫猜想:验证哥德巴赫猜想:
8、21.写结果写结果x02474x1x2x3j3t2#include#include void fun(int a,int i,int j)void fun(int a,int i,int j)int t;int t;while(ij)while(ij)t=ai;ai=aj;aj=t;t=ai;ai=aj;aj=t;i+;j-;i+;j-;void main()void main()int x=2,4,7,4,i;int x=2,4,7,4,i;fun(x,0,3);fun(x,0,3);for(i=0;i4;i+)for(i=0;i4;i+)coutxi;coutxi;i04212474212
9、2:写结果:写结果a01234a1a2a36#include#include void sum(int a)void sum(int a)a0=a-1+a1;a0=a-1+a1;void main()void main()int a10=1,2,3,4,5,6,7,8,9,10;int a10=1,2,3,4,5,6,7,8,9,10;sum(&a2);sum(&a2);printf(%dn,a2);printf(%dn,a2);5678910a4a5a6a7a8a9#include int func(int i)static int f=1;f=f*i;return f;void main(
10、)int i,n,m;n=3;for(i=1;i=n;i+)m=func(i);coutmchinese=86;p1-chinese=86;p1-math=80;p1-math=80;p1-english=90;p1-english=90;strcpy(p1-no,20052380);strcpy(p1-no,20052380);strcpy(p1-name,strcpy(p1-name,王小丫王小丫););结构体指针的成员结构体指针的成员结构体指针名结构体指针名-成员名成员名“.”和和“-”都是取成员运算符,都是取成员运算符,“.”表示取结构体指针表示取结构体指针的的成员,成员,“-”表示取
11、指针所指向的结构体变量的成员。表示取指针所指向的结构体变量的成员。#include#include struct studentstruct student char name20;char name20;int score4;int score4;float average;float average;void main()void main()struct student stud1;struct student stud1;int i;int i;cinstud1.name;cinstud1.name;float sum=0;float sum=0;for(i=0;i4;i+)for(i
12、=0;istud1.scorei;cinstud1.scorei;sum=sum+stud1.scorei;sum=sum+stud1.scorei;stud1.average=sum/4;stud1.average=sum/4;cout stud1.average endl;cout stud1.average endl;#include#include#include#include struct userstruct user char name10;char name10;char password10;char password10;void main()void main()str
13、uct user a4=kate,123,lucy,456,struct user a4=kate,123,lucy,456,jack,789,lily,000;jack,789,lily,000;char na10,pass10;char na10,pass10;int i;int i;cinna;cinna;cinpass;cinpass;for(i=0;i4;i+)for(i=0;i4;i+)if(strcmp(na,ai.name)=0)if(strcmp(na,ai.name)=0)&(strcmp(pass,ai.password)=0)&(strcmp(pass,ai.passw
14、ord)=0)coutcout=4)if(i=4)coutcout用户名密码不正确用户名密码不正确;文件读文件读/写写关闭文件关闭文件定义文件指针定义文件指针打开文件打开文件错错?结束结束TF#include stdio.h#include stdio.hvoid main()void main()int u;int u;FILE FILE*f1,f1,*f2;f2;f1=fopen(a1.dat,r);f1=fopen(a1.dat,r);fscanf(f1,%d,&u);fscanf(f1,%d,&u);printf(u=%d,u-);printf(u=%d,u-);f2=fopen(a2
15、.dat,w);f2=fopen(a2.dat,w);fprintf(f2,u=%d,+u);fprintf(f2,u=%d,+u);fclose(f1);fclose(f1);fclose(f2);fclose(f2);#include#include void main()void main()FILE FILE*fp;fp;int a34;int a34;int i,j;int i,j;for(i=0;i3;i+)for(i=0;i3;i+)for(j=0;j4;j+)for(j=0;j4;j+)scanf(%d,&aij);scanf(%d,&aij);fp=fopen(A1,w);fp=fopen(A1,w);for(i=0;i3;i+)for(i=0;i3;i+)for(j=0;j4;j+)for(j=0;j4;j+)fprintf(fp,%4d,aij);fprintf(fp,%4d,aij);fprintf(fp,n);fprintf(fp,n);fclose(fp);fclose(fp);