Advertisement
madalinaradu

P27-Mandelbrot

Apr 29th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4.  
  5. class Complex{
  6. private:
  7.     float real;
  8.     float imaginar;
  9. public:
  10.  
  11.     Complex(float real=0, float imaginar = 0){
  12.         this -> real = real;
  13.         this -> imaginar = imaginar;
  14.     }
  15.  
  16.     void afisare(){
  17.         printf("%8.4f %+8.4f*i\n", real, imaginar);
  18.     }
  19.  
  20.     Complex operator + (const Complex &z){
  21.         return Complex(real+z.real, imaginar + z.imaginar);
  22.     }
  23.  
  24.     Complex operator * (const Complex &z){
  25.         return Complex(real*z.real - imaginar*z.imaginar, real*z.imaginar + imaginar*z.real);
  26.     }
  27. };
  28.  
  29. Complex c(-1.0,.35);
  30.  
  31.  
  32. Complex f(int n){
  33.     if(n == 0)
  34.         return c;
  35.     else {
  36.         Complex z = f(n-1);
  37.         return z*z + c;
  38.     }
  39.  
  40.  
  41. }
  42. int main(){
  43.     Complex z;
  44.     int n=10;
  45.     for(int i=0;i<n;i++){
  46.       z = f(i);
  47.       printf("f(%d)=",i);
  48.       z.afisare();
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement