#include "stdio.h" int main(){ int x[3][2]={0},i; for(i=0;i<3;i++) scanf("%d",x[i]); printf("%3d%3d%3d\n",x[0][0],x[0][1],x[1][0]); return 0; }
#include "stdio.h" int m1(int x,int y) { if(x<=y) return 2*x+1; else return y; } int m2(int x,int y) { if(x<=y) return 2*y+1; else return x; } int main(){ int i,t1=10,t2=0; for(i=1;i<=4;i++) { t1=m1(i,t1); t2=m2(i,t2); } printf("t1=%d t2=%d\n",t1,t2); return 0; }
#include "stdio.h" char *a="GOODNEWYEAR"; char b[]="goodnewyear"; int main(){ int i=0; printf("%c%s\n",*a,b+7); return 0; }
a既指向G又指向字符串,b同理
#include "stdio.h" int main(){ char ss[3][5]={"aaaa","bbbb","cccc"}; int i=0; do { ss[i][++i]=0; } while (i<3); do { puts(ss[i-1]); } while (--i>0); return 0; }
递归的题目:答案是10
#include "stdio.h" int fun(int a[],int k) { if(k==0)return (a[0]); return a[0]+fun(a+1,k-1); } int main(){ int a[]={1,2,3,4,5}; printf("%d",fun(a,3)); }
| 取不同的 &取相同的
#include "stdio.h" int main(){ unsigned char a=2,b=4,c=5,d; d=a|b; d&=c; printf("%d\n",d); }
返回结构体的函数
#include "stdio.h" #include "string.h" typedef struct { char name[9]; char sex; int score[2]; }STU; STU f(STU a){ STU b={"Zhao",'m',85,90}; int i; strcpy(a.name,b.name); a.sex=b.sex; for(i=0;i<2;i++) a.score[i]=b.score[i]; return a; } int main(){ STU c={"Qian",'f',95,92},d; d=f(c); printf("%s,%c,%d,%d",d.name,d.sex,d.score[0],d.score[1]); printf("%s,%c,%d,%d",c.name,c.sex,c.score[0],c.score[1]); }