









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










double silly_sum ( int a , double b ) { return a + b ; }
void Super_Void ( void ) { return ; }
void Super_Void ( ) { return ; }
void Super_Void ( void ) { }
void Super_Void ( ) { }
using namespace std ; / ∗ ∗∗ ∗ r e t u r n s t h e area , v a l u e s d i a m e t e r and c i r c ∗ / double CircleMeasures ( double r , double & diameter , double & circ ) { const double PI ( acos ( -1)); diameter = 2* r ; circ = diameter * PI ; / / or , 2 ( p i ) r i f y ou l i k e return PI * pow (r ,2); / / a r e a i s p i ∗ r }
4 int add_two ( int a , int & b ) 5 { 6 b -= 1; 7 a += 1; 8 return a + b; 9 } 10 11 int add_three ( int a , int & b , int c ) 12 { 13 return add_two ( add_two ( a , b ) , c ); 14 } 15 16 int main () 17 { 18 int a = 10; 19 int b = 20; 20 int c = 0; 21 22 cout << add_three ( a , b , c ) << " " ; 23 cout << a << " " << b << " " << c ; 24 cout << endl ; 25 26 return 0; 27 }
3 void f( int x , double y ); 4 int f ( const string & s , int x ); 5 double f ( string & s , int x ); 6 double f ( string & s , double y ); 7 8 int main () 9 { 10 const string greeting ( " hello " ); 11 string farewell ( " good - bye " ); 12 int i ( f( greeting , 3 )); 13 f ( i , f ( farewell , 3.0 )); 14 return 0; 15 }
3 void f( int & x ); 4 void f( const int & ) const ; 5 bool f( int & ); 6 bool f( double y ); 7 bool f( int ); 8 bool f( double x ); 9 void f( int x ); 10 void f ();
1 # include < string > 2 # include < cmath > 3 using namespace std ; 4 5 int f ( int a ); 6 7 string g ( double f ); 8 9 void h ( int m , string & n ) 10 { 11 return ; 12 } 13 14 int main () 15 { 16 double product = j (); 17 string text ( " abc " ); 18 int result ; 19 double product_string ; 20 21 product_string = g( product ); 22 23 result = h ( f ( ’A ’ )+ h (0 , text ) , " xyz " ); 24 25 return 0; 26 } 27 28 double j ( void ) 29 { 30 return acos ( -1)* exp (1); 31 } 32 33 double f ( int a ) 34 { 35 return j () + a ; 36 }
n
i = 1
∞
n = 0
n
i = 1
(^1) It is connected to the golden ratio in an incredibly elegant way. (^2) The minimal packing pattern of sunflower seeds, the turns and ridges of sea shells,...
The average of 1 and 0 zeros is 1 The average of 1 and 1 zeros is 0. The average of 1 and 2 zeros is 0. The average of 1 and 3 zeros is 0. The average of 1 and 4 zeros is 0. The average of 1 and 5 zeros is 0. The average of 1 and 6 zeros is 0. The average of 1 and 7 zeros is 0. The average The average of 1 andof 1 and 8 zeros9 zeros is 0.111111is 0. The average of 1 and 10 zeros is 0. The average of 1 and 11 zeros is 0. The average of 1 and 12 zeros is 0. The average of 1 and 13 zeros is 0. The average of 1 and 14 zeros is 0. The average of 1 and 15 zeros is 0. The average of 1 and 16 zeros is 0. The average of 1 and 17 zeros is 0. The average of 1 and 18 zeros is 0. The average of 1 and 19 zeros is 0. The first 20 Fibonacci terms are 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 Fib term 1 is closest to - Fib term 6765 is farthest from - Fib term 6765 is closest to 10000 Fib term 1 is farthest from 10000 Fib term 4181 is closest to 4184 Fib term 1 is farthest from 4184 Fib term 2584 is closest to 2585 Fib term 6765 is farthest from 2585 Fib term 5 is closest to 6 Fib term 6765 is farthest from 6 sin(3/2 * PI) = -1 (should be -1) sin(1) = 0.841471 (should be 0.84147...)
2 ∗ C a l c u l a t e an a v e r a g e 3 ∗ / 4 double average ( const double data [] , const int size ) 5 { 6 double sum (0); 7 for ( int i (0); i < size ; i ++ ) { 8 sum += data [i ]; 9 } 10 11 return sum / size ; 12 } 13 14 / ∗ ∗∗ 15 ∗ F i b o n a c c i 16 ∗ / 17 void fibonacci ( int fib [] , const int size ) 18 { 19 / / 1 , 1 , 2 , 3 , 5 , 8 , 1 3 ,... 20 if ( size >= 1 ) { 21 fib [0] = 1; 22 } 23 if ( size >= 2 ) { 24 fib [1] = 1; 25 } 26 / / f i l l i n t h e r e s t 27 for ( int i (2); i < size ; i ++ ) { 28 fib [ i ] = fib [i -2] + fib [i -1]; 29 } 30 } 31 32
79 ∗ s i n e t e r m s 80 ∗ / 81 void sine_terms ( double terms [] , const int size , double x ) 82 { 83 / / be s a f e 84 if (! size ) return ; 85 86 / / t h e f a c t o r i a l t e r m 87 int factterm (1); 88 / / t h e d e n o m i n a t o r f a c t o r i a l v a l u e 89 double fact (1); / / f a c t o r i a l o f d e n o m i n a t o r 90 / / t r a c k s t h e s i g n o f eac h t e r m 91 double neg (1); / / f i r s t t e r m i s p o s i t i v e 92 / / t h e c u r r e n t pow er o f x 93 double powx ( x ); 94 / / pow ers o f x i n c r e a s e by x s q u a r e d 95 double xsquared (x * x ); 96 97 / ∗ ∗∗∗ 98 ∗ N ot e t h a t neg , powx , and f a c t a r e a l r e a d y i n i t i a l i z e d 99 ∗ f o r t h e f i r s t t e r m 100 ∗ / 101 102 for ( int i (0); i < size ; i ++ ) { 103 / / f i l l i n t h e t e r m 104 terms [i ] = ( neg * powx )/ fact ; 105 / ∗ ∗∗∗ 106 ∗ c a l c u l a t e d f a c t o r s f o r t h e n e x t t e r m 107 ∗ / 108 / / s i g n c hange 109 neg = - neg ; 110 / / n u m e r a t o r = n u m e r a t o r ∗ x ∗ x 111 powx *= xsquared ; 112 / / f a c t o r i a l i n c r e a s e s by t w o i n t e g e r v a l u e s 113 fact *= ++ factterm ; 114 fact *= ++ factterm ; 115 } 116 } 117 118
120 ∗ s i n e s u m s 121 ∗ / 122 double sine_sums ( double terms [] , const int size , double x , double sums [] ) 123 { 124 / / g e t t h e t e r m s 125 sine_terms ( terms , size , x ); 126 127 / / c a l c u l a t e p a r t i a l sums 128 double s (0); 129 for ( int i (0); i < size ; i ++ ) { 130 s += terms [ i ]; 131 sums [ i] = s ; 132 } 133 134 / / r e t u r n t h e p a r t i a l sum o f t h e f i r s t s i z e t e r m s 135 return sums [ size -1]; 136 }
25 void Ax ( const double A [ MAXP ][ MAXP ] , const double x [] , 26 double product [] , const int p ) 27 { 28 / / f o r eac h row o f t h e m a t r i x A 29 for ( int arow (0); arow < p ; arow ++ ) { 30 double sum (0); 31 / / f o r eac h c om ponent o f t h e v e c t o r 32 for ( int xrow (0); xrow