I'm new to coding and was given an assigment to approximate the value of pi through the Leibniz's formula. This is what I wrote but it's taking forever to compile. I've tried to debug it but with no success.
#include <stdio.h>
#include <math.h>
float pi(int n);
int main(){
int n;
printf("enter the number of terms: ");
scanf("%f", &n);
if(n < 1){
printf("the number needs to be greater than 0. try again: ");
scanf("%f", &n);
printf("%.6f", pi(n));
}
else{
printf("%.6f", pi(n));
}
return 0;
}
float pi(int n){
float sum = 1; //first element of summation is one
for(int i = 1; i < n; i++){
sum += pow(-1, i)/(2 * i) + 1;
}
return 4 * sum;
}