2 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
C語(yǔ)言的程序是:
int num , i , j , root;
scanf ( "%d", &num );//Input the number
root = sqrt( num ); //We don't need to check the square upto input number. Just upto
//Its square root
for( i = 1 ; i < root ; i++ )
{
j = i;
for( ; j < root ; j++ )
{
if( ( ( i*i ) + ( j*j ) ) == num ) //If square is equal to number
{
printf( "%d %d\n",i,j ); //Print the combination
}
}
}

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
此代碼用于 INT 號(hào):$limit => 100
<?php
$limit = 100;
$max_pair_value = ceil(sqrt($limit));
for($i = 0; $i<=$max_pair_value; $i++){
for($j = $i; $j<=$max_pair_value; $j++){
$answer = pow($i,2) + pow($j, 2); //YOUR CONDITION
if($answer == $limit){
$pair[] = [0=>$i, 1=>$j];
}
}
}
print_r($pair); //UNIQUE PAIR
?>
- 2 回答
- 0 關(guān)注
- 168 瀏覽
添加回答
舉報(bào)