读程序写结果一、数组1.#includestdio.hvoidmain(){inta[8]={1,0,1,0,1,0,1,0},i;for(i=2;i8;i++)a[i]+=a[i-1]+a[i-2];for(i=0;i8;i++)printf(“%5d”,a[i]);}2.#includestdio.hvoidmain(){floatb[6]={1.1,2.2,3.3,4.4,5.5,6.6},t;inti;t=b[0];for(i=0;i5;i++)b[i]=b[i+1];b[5]=t;for(i=0;i6;i++)printf(“%6.2f”,b[i]);}3.#includestdio.hvoidmain(){intp[7]={11,13,14,15,16,17,18},i=0,k=0;while(i7&&p[i]%2){k=k+p[i];i++;}printf(k=%d\n,k);}4.voidmain(){inta[3][3]={1,3,5,7,9,11,13,15,17};intsum=0,i,j;for(i=0;i3;i++)for(j=0;j3;j++){a[i][j]=i+j;if(i==j)sum=sum+a[i][j];}printf(sum=%d,sum);}5.voidmain(){inta[4][4],i,j,k;for(i=0;i4;i++)for(j=0;j4;j++)a[i][j]=i-j;for(i=0;i4;i++){for(j=0;j=i;j++)printf(%4d,a[i][j]);printf(\n);}}6.#includestdio.hmain(){inti,s;chars1[100],s2[100];printf(inputstring1:\n);gets(s1);printf(inputstring2:\n);gets(s2);i=0;while((s1[i]==s2[i])&&(s1[i]!='\0'))i++;if((s1[i]=='\0')&&(s2[i]=='\0'))s=0;elses=s1[i]-s2[i];printf(%d\n,s);}输入数据aidand7.voidmain(){charch[3][5]={AAAA,BBB,CC};printf(\%s\\n,ch[1]);}1.10225713202.2.203.304.405.506.601.103.k=244.sum=65.01021032106.-57.“BBB”二、指针1、charcchar(charch){if(ch=‘A’&&ch=‘Z')ch=ch-‘A'+‘a';returnch;}voidmain(){chars[]=ABC+abc=defDEF,*p=s;while(*p){*p=cchar(*p);p++;}printf(%s\n,s);}2、voidmain(){inta[5]={2,4,6,8,10},*p,**k;p=a;k=&p;printf(%d,*(p++));printf(%d\n,**k);}3、funa(inta,intb){returna+b;}funb(inta,intb){returna-b;}sub(int(*t)(),intx,inty){return((*t)(x,y));}voidmain(){intx,(*p)();p=funa;x=sub(p,9,3);x+=sub(funb,8,3);printf(%d\n,x);}4、voidmain(){char*s=12134211;intv[4]={0,0,0,0};intk,i;for(k=0;s[k];k++){switch(s[k]){case'1':i=0;case'2':i=1;case'3':i=2;case'4':i=3;}v[i]++;}for(k=0;k4;k++)printf(%d,v[k]);}5、#includectype.hvoidspace(char*str){inti,t;charts[81];for(i=0,t=0;str[i]!='\0';i+=2)if(!isspace(*(str+i))&&(*(str+i)!='a'))ts[t++]=toupper(str[i]);ts[t]='\0';strcpy(str,ts);}voidmain(){chars[81]={abcdefg};space(s);puts(s);}6、#includestdio.hsub1(chara,charb){charc;c=a;a=b;b=c;}sub2(char*a,charb){charc;c=*a;*a=b;b=c;}sub3(char*a,char*b){charc;c=*a;*a=*b;*b=c;}voidmain(){chara,b;a='A';b='B';sub3(&a,&b);putchar(a);putchar(b);a='A';b='B';sub2(&a,b);putchar(a);putchar(b);a='A';b='B';sub1(a,b);putchar(a);putchar(b);}7、voidmain(){charb[]=ABCDEFG;char*chp=&b[7];while(--chp&b[0])putchar(*chp);putchar('\n');}8、voidprtv(int*x){printf(%d\n,++*x);}voidmain(){inta=25;prtv(&a);}9、intaa[3][3]={{2},{4},{6}};voidmain(){inti,*p=&aa[0][0];for(i=0;i2;i++){if(i==1)aa[i][i+1]=*p+1;else++p;printf(%d,*p);}}10、intf(intb[],intn){inti,r=1;for(i=0;i=n;i++)r=r*b[i];returnr;}voidmain(){intx,a[]={2,3,4,5,6,7,8,9};x=f(a,3);printf(%d\n,x);}1、abc+abc=defdef2、243、174、00085、CEG6、BABBAB7、GFEDCB8、269、0010、120三、结构体1、#includestdio.hstructabc{inta,b,c;};main(){structabcs[2]={{1,2,3},{4,5,6}};intt;t=s[0].a+s[1].b;printf(%d\n,t);}2、#includestdio.hstructstu{intnum;charname[10];intage;};voidfun(structstu*p){printf(%s\n,(*p).name);}voidmain(){structstustudents[3]={{9801,Zhang,20},{9802,Wang,19},{9803,Zhao,18}};fun(students+2);}3、#includestdio.hvoidmain(){enumteam{my,your=4,his,her=his+10};printf(%d%d%d%d\n,my,your,his,her);}4、#includestdio.hstructst{intx;int*y;}*p;intdt[4]={10,20,30,40};structstaa[4]={50,&dt[0],60,&dt[1],70,&dt[2],80,&dt[3]};voidmain(){p=aa;printf(%d,,++p-x);printf(%d,,(++p)-x);printf(%d\n,++(*p-y));}5、#includestdio.hunionmyun{struct{intx,y,z;}u;intk;}a;voidmain(){a.u.x=4;a.u.y=5;a.u.z=6;a.k=0;printf(%d\n,a.u.x);}6、#includestdio.hstructSTU{charnum[10];floatscore[3];};voidmain(){structSTUs[3]={{“20021”,90,95,85},{“20022”,95,80,75},{“20023”,100,95,90}},*p=s;inti;floatsum=0;for(i=0;i3;i++)sum=sum+p-score[i];printf(“%6.2f\n”,sum);}7、#includestdio.h#includestdlib.hstructNODE{intnum;structNODE*next;};voidmain(){structNODE*p,*q,*r;p=(structNODE*)malloc(sizeof(structNODE));q=(structNODE*)malloc(sizeof(structNODE));r=(structNODE*)malloc(sizeof(structNODE));p-num=10;q-num=20;r-num=30;p-next=q;q-next=r;printf(“%d\n”,p-num+q-next-num);}8、#includestdio.htypedefunionstudent{charname[10];longsno;charsex;floatscore[4];}STU;voidmain(){STUa[5];printf(“%d\n”,sizeof(a));}1、62、Zhao3、045154、51,60,215、06、270.007、408、80