i need help translating this code into c language. PROGRAM IMPLICIT NONE INTEGER
ID: 3611116 • Letter: I
Question
i need help translating this code into c language.PROGRAM
IMPLICIT NONE
INTEGER::divx,i
REAL(kind=8)::approx,approx1,delx,x,count
delx=0
divx=0
approx=0
count=0
DO
count=count+1
divx=divx*2
delx/1./divx
x=0
approx1=0
DOi=1,divx
delx=1./divx
x=x+delx
approx1=approx1+delx*sqrt(1-x**2)
ENDDO
IF (abs(approx1-approx)<.00000001)EXIT
approx=approx1
END DO
WRITE(*,*)'pi=',approx*4
WRITE(*,*)'number of iterations:',count
END PROGRAM
pretty simple program but i dont know how to write in thec-language yet. please help
Explanation / Answer
please rate - thanks I changed count to integer instead of double, I started divx at 1 instead of 0 FORTRAN is really much better for this #include #include #include #include int main() {int divx,i,count; double approx,approx1,delx,x; delx=0; divx=1; approx=0; approx1=0; count=0; do {approx=approx1; count++; divx*=2; delx=1./divx; x=0; approx1=0; for(i=1;i.00000001); printf("pi = %lf ",approx1*4); printf("number of iterations: %d ",count); getch(); return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.