做電商哪個設(shè)計網(wǎng)站比較好東莞最新消息今天
題干
在數(shù)學里面,有一種數(shù)字正著讀和反著讀結(jié)果都一樣,我們把這種數(shù)稱為回文數(shù)。如果一個回文數(shù),它同時還是某一個數(shù)的平方,這樣的數(shù)字叫做平方回數(shù)。
本題要求輸出小于正整數(shù)N的所有平方回數(shù)。
(注:個位數(shù)都是回文數(shù)。)
函數(shù)接口定義:
void Squared_Symmetry ( const int N );
其中 N 是用戶傳入的參數(shù)。 N 的值不超過int的范圍。
裁判測試程序樣例:
在這里給出函數(shù)被調(diào)用進行測試的例子。例如:
#include <stdio.h>void Squared_Symmetry ( const int N );int main()
{int N;scanf("%d", &N);Squared_Symmetry(N);return 0;}/* 請在這里填寫答案 */
輸入樣例:
在這里給出一組輸入。例如:
1000
輸出樣例:
在這里給出相應的輸出。例如:
676 484 121 9 4 1
#include<math.h>
int isPalindrome(int num) {int originalNum = num;int reversedNum = 0;while (num > 0) {int remainder = num % 10;reversedNum = reversedNum * 10 + remainder;num /= 10;}return originalNum == reversedNum?1:0;
}
void Squared_Symmetry(const int N){double n=N;int temp,i;n=sqrt(n);temp=(int) n;for(i=N;i>=1;i--){n=i;n=sqrt(n);temp=(int) n;if(n-temp==0&&isPalindrome(i)){if(i==1){printf("%d\n",i);return ;}printf("%d ",i);}}
}