用c语言求1到1000的同构数
导读:收集整理的这篇文章主要介绍了用c语言求1到1000的同构数,觉得挺不错的,现在分享给大家,也给大家做个参考。具体请看实例:免费视频教程推荐:c语言视频教程#include<stdio.h>#include<stdlib.h...
收集整理的这篇文章主要介绍了用c语言求1到1000的同构数,觉得挺不错的,现在分享给大家,也给大家做个参考。具体请看实例:
免费视频教程推荐:c语言视频教程
#includestdio.h>
#includestdlib.h>
#includestring.h>
char *right(char *ms,int len);
/*截取一个字符串尾部长为len个字符的子串*/void main(){
long a;
int len;
char as[10];
char ms[20];
PRintf("求[1,10000]中的同构数:\n");
for(a=1;
a=10000;
a++){
ultoa(a,as,10);
/*数a转换为字符串,存入as*/len=strlen(as);
ultoa(a*a,ms,10);
if(strcmp(as,right(ms,len))==0) /*比较字符串as与ms长为len的子串是否相等*/printf("%s 其平方为 %s\n",as,ms);
/*相等就是同构数,输出结果*/}
System("pause");
}
char *right(char *ms,int len) /*截取字符串尾部长为len子串的函数*/{
int i,j;
for(i=0;
i(signed)strlen(ms);
ms++);
for(j=0;
jlen;
j++,ms--);
return ms;
}
相关文章教程分享:c语言教程
以上就是用c语言求1到1000的同构数的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 用c语言求1到1000的同构数
本文地址: https://pptw.com/jishu/593730.html
