Sum of Series

Problem Statement:

Program to compute and display the sum of the following series up to n-terms:
X - X/2 + X/3 - X/4 +…

Source Code:
#include<stdio.h>
int main(){
    int x, n;
    float sum = 0.0;
    scanf("%d",&x);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        if(i%2==1){
            sum = sum + (float)x/i;
        }else{
            sum = sum - (float)x/i;
        }
    }
    printf("%.2f",sum);
    return 0;
}
SAMPLE INPUT:
12
5
SAMPLE OUTPUT:
9.40