Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. float valoreAssoluto(float x){
  4.     if(x>=0){
  5.         return x;
  6.     }else{
  7.         return x*(-1.0);
  8.     }
  9. }
  10.  
  11. float radice(float a) {
  12.   float x = 1.0;
  13.   while (valoreAssoluto(x * x - a) > 1e-5)
  14.     x = (x + a / x) / 2.0;
  15.   return x;
  16. }
  17.  
  18. float f(int n){
  19.     return radice((n-1.0)/(n+1.0));
  20. }
  21.  
  22.  
  23. int main(){
  24.     int a,b;
  25.  
  26.     printf("inserisci 2 numeri N \n");
  27.     scanf("%d %d",&a,&b);
  28.    
  29.     while(a<=b){    // a<=x<=b
  30.         if(a%2==0){
  31.             printf("\n%f\n",f(a));
  32.         }else{
  33.             printf("\n %d\n",a);
  34.         }
  35.         a++;
  36.     }
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement