Created
September 17, 2014 09:04
-
-
Save metrafonic/58530db91d43b953f04e to your computer and use it in GitHub Desktop.
Oppgave4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <conio.h> | |
#include <math.h> | |
int main(){ | |
int i = 0; | |
double pi = 1, piresult=0; | |
int pides=1; | |
double faktor=0, pi10desimaler=1, pinew=0, piold=0, pidiff=0; | |
float j =0, stop=0,ipotens=0; | |
printf("Oppgave 4. Del 1 av 2\nRegner pi for noeyaktig 10 siffer\nTar ca 30 sek\nDen vil stoppe naar verdien den regner delt paa verdien av pi i virkeligheten blir 1, altsaa piregnet/pi(10 siffer)=1\n\nPlease Wait...\n\n"); | |
for(i=1;pides!=0;i++){ | |
if ( i%2 == 0 ){ | |
pi=pi+(double)1/(1+i*2); | |
piresult=pi*4; | |
pinew=pi; | |
pidiff=pi*4+((double)(pinew-piold)/2); | |
//printf("%.9f\n", pidiff); | |
}else{ | |
pi=pi-(double)1/(1+i*2); | |
piresult=pi*4; | |
piold=pi; | |
} | |
//printf("%f", piresult); | |
if((double)((int)((piresult-3)*1000000000))/141592653==1){ | |
pides=0; | |
} | |
} | |
printf("Antall ganger kjoert: %i.\nVerdien av pi: %.9f\n\n\n", i, piresult); | |
piresult=0; | |
pi=0; | |
//getch(); | |
printf("Oppgave 4. Del 2 av 2\nRegner pi for noeyaktig 10 siffer\nTar ca 2 sek\n"); | |
for (j=1; pi10desimaler!=0; j++){ | |
ipotens= j*j; | |
pi=pi+((double)1/(ipotens)); | |
piresult=(double)sqrt(pi*6); | |
//pi10desimaler= (int)((double)((double)(piresult*10000000)-(double)(31415926))*100000); | |
if((double)((int)((piresult-3)*1000000000))/141592653==1){ | |
pi10desimaler=0; | |
} | |
} | |
printf("Antall ganger kjoert: %.0f.\nVerdien av pi: %.9f\n", j, piresult); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment