Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "mycolor.h"
- void main()
- {
- double radicand, start, quotient, next_value, precision, result;
- int max;
- system("clear");
- printf("Radicand: ");
- scanf("%lf", &radicand);
- if(radicand > 10000000){
- RED printf("This radicand is too big!\n"); RESET
- }
- else{
- system("clear");
- start = radicand / ((radicand + 1) / 4); // Erzeugt einen Startwert für die erste Iteration.
- quotient = radicand / (start * start); // Überprüft den Startwert und erzeugt einen neuen Wert für alle weiteren Iterationen.
- next_value = ((quotient + 2 * start) / 3); // Erster Wert für dei for-Schleife.
- if(radicand <= 10){ // Diese if-Anweisungen legen nach größe des Radikanden fest wie oft die Schleife laufen soll.
- max = 5;
- }
- else if(radicand > 10){
- max = 25;
- }
- else if(radicand > 100){
- max = 100;
- }
- for(precision = 1; precision <= max; precision++){
- system("clear");
- result = radicand / (next_value * next_value); // Der gleiche Vorgang wie oben bei quotient.
- next_value = ((result + 2 * next_value) / 3); // Der gleiche Vorgang wie oben bei next_value.
- if(precision == max){ // Damit das Zählen, b.z.w. der Schleifendurchlauf unsichtbar bleibt.
- printf("Cube root oot of %.5lf is %.5lf\n", radicand, next_value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement