36: Calculate the polynomial value. 36: Calculate the polynomial.

Source: Internet
Author: User
Tags float range

36: Calculate the polynomial value. 36: Calculate the polynomial.
36: Calculate the polynomial Value

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Assume that the polynomial form is xn + xn-1 +... + X2 + x + 1: calculate the value of this polynomial when given single-precision floating point number x and positive integer n.

Input
Enter only one line, including x and n, separated by a single space. X is in the float range, n <= 1000000.
Output
Output a real number, that is, the polynomial value, accurate to two digits after the decimal point. Ensure that the final result is within the float range.
Sample Input
2.0 4
Sample output
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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.