算法竞赛入门经典 aabb

版权声明:转自可爱的安安的博客!qq:1085589289 https://blog.csdn.net/ac1085589289/article/details/86483081

题目

输出所有形如aabb的4位完全平方数(即前两位数字相等,后两位数字也相等)。

代码

#include<stdio.h>
#include<math.h>
int main()
{
   int a,b;
   for(a=1;a<=9;a++)
   {
   	for(b=0;b<=9;b++)
   	{
   		int n=a*1100+b*11;
   		int m=floor(sqrt(n)+0.5);//floor(x)返回不超过x的最大整数
   		if(m*m==n) printf("%d\n",n); 
   	}
   }
   return 0;
} 

猜你喜欢

转载自blog.csdn.net/ac1085589289/article/details/86483081