C 练习(二)
字符串连接 strcmp #include <stdio.h> void main(){ char c1[] = "Hello ", c2[]="WORLD", c3[13]; int i,j,k; i=j=k=0; while(c1[i] != '\0' || c1[j] != '\0'){ if(c1[i] != '\0'){ c3[k] = c1[i++]; }else{ c3[k] = c2[j++]; } k++; } c3[k]= '\0'; puts(c3); }
杨辉三角
#include <stdio.h> void main(){ int i,j,test[10][10]; for(i=0;i<10;i++){ test[i][0] = 1; test[i][i] = 1; } for(i=2;i<10;i++){ for(j=1;j<i;j++){ test[i][j] = test[i-1][j]+test[i-1][j-1]; } } for(i=0;i<10;i++){ for(j=0;j<=i;j++){ printf("%d\t",test[i][j]); } printf("\n"); } }
生命只有一次。