36:計算多項式的值


36:計算多項式的值

總時間限制: 
1000ms
 
內存限制: 
65536kB
描述

假定多項式的形式為xn+xn-1+…+x2+x+1,請計算給定單精度浮點數x和正整數n值的情況下這個多項式的值。

輸入
輸入僅一行,包括x和n,用單個空格隔開。x在float范圍內,n <= 1000000。
輸出
輸出一個實數,即多項式的值,精確到小數點后兩位。保證最終結果在float范圍內。
樣例輸入
2.0 4
樣例輸出
31.00


 1 de<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     float x;
 9     int n;
10     float tot=0;
11     cin>>x>>n;
12     int a=n;
13     for(int i=n;i>=1;i--)
14     {
15         tot=tot+pow(x,a);
16         a--;
17     }
18     printf("%.2f",tot+1);
19     return 0;
20 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM