用c语言求1到1000的同构数

用c语言求1到1000的同构数,第1张

用c语言求1到1000的同构数

具体请看实例:

免费视频教程推荐:c语言视频教程

#include<stdio.h>
#include<stdlib.h>
#include<string.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;j<len;j++,ms--);
return ms;
}

相关文章教程分享:c语言教程

以上就是用c语言求1到1000的同构数的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/686250.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存