资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
c语言 一些小代码矩阵转置Int main() int A33; int B33; int i,j; for (i=0;i3;i+) for (j=0;j3;j+) scanf(%d,&Aij); /*found*/ for (i=0;i3;i+) for(j=0;j3;j+) Bji=Aij; /*found*/ printf(The reversed matrix is:n); for (i=0;i3;i+) for (j=0;j3;j+) printf(%4d,Bij); printf(n); return 0; 枚举四季#includeenum seasonspring,summer,autumn,winter;typedef struct dateint year,month,day;date;int main()date d;enum season s;scanf(%d%d%d,&d.year,&d.month,&d.day);if(d.month=3&d.month=6&d.month=9&d.month=11)s=autumn;else if(d.month=12|d.month=1|d.month=2)s=winter;switch(s)case spring:printf(NOW it is Springn);break;case summer:printf(NOW it is Summern);break;case autumn:printf(NOW it is Autumnn);break;case winter:printf(NOW it is Wintern);break;求最大公约数#include int gcd(int m,int n) int r; /*found*/ r=m%n; while(r) m=n; n=r; r=m%n; return n; /*found*/ int main() int a,b; scanf(%d%d,&a,&b); printf(%dn,gcd(a,b); return 0; 删除相同元素只留下一个#include int fun(int a,int n) int i,j,k; for(i=0;in-1;i+) for(j=i+1;jn;j+) if(ai=aj) for(k=j;kn;k+) ak=ak+1; j-;n-; return n; int main() int a100,i,n,num; scanf(%d,&n); for(i=0;in;i+) scanf(%d,&ai); num=fun(a,n); for(i=0;inum;i+) printf(%5d,ai); printf(n); return 0; 字符串转值#include int change(char *m,char *des) int i=0; while(*m) if(*m=0&*m=9) desi+=*m; m+; desi=0; return i; double calcu(char*s) double result=0; while(*s) result=result*10+(s0-48); s+; return result; int main() char str50,trades50; gets(str); if(change(str,trades) printf(%.4fn,calcu(trades); else printf(the digital string is empty!n); return 0;
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号