Tính S(x,n) = x +x^2+x^3+...+x^n

BÀI TOÁN
Viết chương trình tính S(x,n) = x +x^2+x^3+...+x^n với x, n được nhập từ bàn phím.

CHƯƠNG TRÌNH THAM KHẢO

Code:

#include "conio.h"
#include "stdio.h"

float Power(float x, unsigned int n) {
    float temp = 1;
    for(int i = 0; i<n; i++)
        temp*= x;
    return temp;
}
double Sum(float x, unsigned int n) {
    double temp = 0;
    for(int i = 1; i<=n; i++)
        temp+= Power(x,i);
    return temp;
}
void main(){
    clrscr();
    unsigned int n;
    float x;
    printf("Nhap vao n = ");
    scanf("%d",&n);
    printf("Nhap vao x = ");
    scanf("%f",&x);
    printf("S = %.2f",Sum(x,n));
    getch();
}