.


:




:

































 

 

 

 


Int sgr_of_power(int x, int n)




{ // x n

if (n==2) //, x

return x * x;

else // sgr_of_power

return (x * sgr_of_power(x, n-1));

}

 

++.

, , . 2.1.

 

2.1 ++

< cmath > .
< cstdlib > , , .
< cstring > ( ).
< cctype > .
< time >

 

2_5_1.

#include <cstdlib>

#include <iostream>

using std::endl;

using std::cout;

 

Int main()

{

for (int i =0; i <=20; ++ i)

cout<<(1 + rand()%6)<<endl; // 1 6:

// rand()

// 0 RAND_MAX( 32767)

system("pause");

return 0;

}

 

2_5_2.

#include <ctime>

#include <iostream>

using std::endl;

using std::cout;

 

Int main()

{

time_t system_time = time(NULL); // NULL

cout<<"System time: "<<ctime (&system_time)<<endl;

system("pause");

return 0;

}

 

:

 

 

 

, , . ++ , .

 

2_6_1.

#include <iostream>

using std::endl;

using std::cout;

 

int square(int x){ return x * x;}

double square(double y){ return y * y;}

Int main()

{

cout<<" 7 = " <<square(7) <<endl;

cout<<" 7.5 = "<<square(7.5)<<endl;

system (" pause ");

return 0;

}

 

square (7) int square (int x) 49. double square (double y) 56.25.

 

, . .

2_6_2.

#include <iostream>

using std::endl;

using std::cout;

 

template <typename T> //

T square(T value){ return value * value;} // T

 

Int main()

{

cout<<" 7 = " <<square(7) <<endl;

cout<<" 7.5 = "<<square(7.5)<<endl;

system (" pause ");

return 0;

}

 

square , T , square . . , , .

 

 





:


: 2018-10-14; !; : 277 |


:

:

,
==> ...

1702 - | 1471 -


© 2015-2024 lektsii.org - -

: 0.009 .