Advertisement
Guest User

Cube root algorithm

a guest
Jan 26th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. void main()
  6. {
  7.     double radicand, start, quotient, next_value, precision, result;
  8.  
  9.     int max;
  10.    
  11.    
  12.    
  13.     system("clear");
  14.    
  15.     printf("Radicand: ");
  16.    
  17.     scanf("%lf", &radicand);
  18.    
  19.    
  20.     if(radicand > 10000000){
  21.    
  22.         printf("This radicand is too big!\n");
  23.     }
  24.  
  25.     else{
  26.    
  27.     system("clear");
  28.    
  29.     start = radicand / ((radicand + 1) / 4);
  30.    
  31.     quotient = radicand / (start * start);
  32.    
  33.     next_value = ((quotient + 2 * start) / 3);
  34.    
  35.    
  36.     if(radicand <= 10){
  37.    
  38.         max = 5;
  39.     }
  40.    
  41.     else if(radicand > 10){
  42.    
  43.         max = 25;
  44.     }
  45.    
  46.     else if(radicand > 100){
  47.    
  48.         max = 100;
  49.     }
  50.        
  51.         for(precision = 1; precision <= max; precision++){
  52.    
  53.             system("clear");
  54.            
  55.             result = radicand / (next_value * next_value);
  56.        
  57.             next_value = ((result + 2 * next_value) / 3);
  58.            
  59.             if(precision == max){
  60.            
  61.                 printf("Cube root oot of %.5lf is %.5lf\n", radicand, next_value); 
  62.             }  
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement