【文章內(nèi)容簡介】
,比較與原數(shù)是否相等,若相等,則原數(shù)為回文。 函數(shù)的聲明與使用 include iostream using namespace std。 //判斷 n是否為回文數(shù) bool symm(unsigned n) { unsigned i = n。 unsigned m = 0。 while (i 0) { m = m * 10 + i % 10。 i /= 10。 } return m == n。 } 14 int main() { for(unsigned m = 11。 m 1000。 m++) if (symm(m) amp。amp。 symm(m * m) amp。amp。 symm(m * m * m)) { cout m = m。 cout m * m = m * m。 cout m * m * m = m * m * m endl。 } return 0。 } 15 運行結(jié)果: m=11 m*m=121 m*m*m=1331 m=101 m*m=10201 m*m*m=1030301 m=111 m*m=12321 m*m*m=1367631 16 程序設(shè)計 (第 3章 函 數(shù) ) 主講教師:張鵬祥 17 例 35 計算如下公式,并輸出結(jié)果: 其中 r、 s的值由鍵盤輸入。 sin x的近似值按如下公式計算,計算精度為 106: 函數(shù)的聲明與使用 ?????????????1121753)!12()1(!7!5!3!1s i nnnnnxxxxxx ?2 2 2 222s in s in r1 s in ( ) r2r s skr s s? ????????當(dāng)當(dāng)include iostream include cmath //對 C++標(biāo)準(zhǔn)庫中數(shù)學(xué)函數(shù)的說明 using namespace std。 const double TINY_VALUE = 1e10。 double tsin(double x) { double g = 0。 double t = x。 int n = 1。 do { g += t。 n++。 t = t * x * x / (2 * n 1) / (2 * n 2)。 } while (fabs(t) = TINY_VALUE)。 return g。 } 18 int main() { double k, r, s。 cout r = 。 cin r。 cout s = 。 cin s。 if (r * r = s * s) k = sqrt(tsin(r) * tsin(r) + tsin(s) * tsin(s))。 else k = tsin(r * s) / 2。 cout k endl。