1. , . . . .
2. , . n , n (, n ). .
3. , . . . .
4. , . n , n (, n ). .
5. , . . . .
6. , . n , n (, n ). .
7. , . , ( ).
8. , . , ( ). .
9. , . , .
10. , . , .
11. , . , .
12. , . , .
13. , . , ( ).
14. , . , //
15. , . /**/
16. , . , .
17. , . , .
18. , . , , ( 1 ).
|
|
19. , . , .
20. , . , , .
21. , ( , ). , ( ).
22. , . , , ( ).
23. , ( , ). , : , , .
24. , , :
, , , , , , .
.
25. , , : , , , , .
, ( ).
26. , , : , , -, , .
.
27. , , : , , , .
.
28. , , : , , , , .
, .
29. , , , : , , , , .
, .
30. , , , : , , -, , , .
, , .
6
: , .
1. A(50) [-20, 30] . .
, .
#include<iostream>
#include<iomanip>
|
|
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
using namespace std; //
/* , ( , ): */
void swap(int& a, int& b)
{
int c;
c=a; a=b; b=c;
}
//
void sort(int* a, int n)
{
for (int i = 1; i < n; i++) //
for (int j = 0; j < n-i; j++) //
{
if (a[j] > a[j+1]) //
swap(a[j], a[j+1]); //
}
}
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
int n=50;
int *a=new int[n]; // 50
cout<<" :\n";
//
int RANGE_MIN = -20; //
int RANGE_MAX = 51; //
// ms-help: //MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vccrt/html/75d9df25-7aaf-4a88-b940-2775559634e8.htm
for (int i = 0; i < n; i++)
{
a[i] = (int)(((double) rand() / (double) RAND_MAX) * RANGE_MAX + RANGE_MIN); // [-20, 30]
cout << setw(4) << a[i]; /* ( 4 */
}
cout <<endl;
// :
sort(a, n);
printf("\n, :\r\n");
// :
for (int i = 0; i < n; i++)
{
printf("%4d", a[i]); //
}
printf("\r\n"); //
_getch();
return 0;
}
2. , n .
.
:
1
x, : x1 = 2 ( ).
:
a0 a1 a2 an-1
+ -a0xn -a1xn -an-2xn an-1xn
: 2 3 :
(x-2)(x+3) = x2-2x+3x-6 =1x2 + 1x 6
1 -2
+ -1(-3) (-2)(-3)
---------------------------
1 1 -6
, , , .
#include<iostream>
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
do
{
int n; //
do
{
cout << " > 0 --> ";
cin >> n;
} while (n < 1);
double* x = new double [n]; //
double* a = new double [n+1]; //
a[0] = 1; //
cout << " :\n";
for (int i = 0; i < n; i++)
{
cout<< i+1 <<"- --> ";
|
|
cin >> x[i];
a[i+1] = -a[i] * x[i];
//
// :
for (int j = i; j >= 1; j--)
a[j] += -a[j-1] * x[i];
}
// :
cout << " : ";
for (int i = 0; i < n; i++)
cout << x[i]<<" ";
cout << endl;
cout << " : ";
for (int i=0; i<=n; i++)
cout << a[i]<<" ";
cout << endl;
delete []x;
delete []a;
cout<<" Esc\n";
}while(_getch()!=27);
return 0;
}
3. , , , min max .
, , ( , )
#include<iostream>
#include<locale> //!!!
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
#include<fstream> //
using namespace std;
/* , , */
ifstream file("test.txt");
// , :
void ShowIndex(int, float);
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
if(!file)
{
cerr<<" test.txt \n";
return 0;
}
float n, min, max; // , ,
int k=0; //
while (1) //
{
file>>n;
if (file.eof()) break;
// ,
if (!k) // (k=0)
{
min = n;
max = n;
}
else //
{
if (n<min) min=n;
// , min
if (n>max) max=n;
// , max
}
cout<<n<<' '; k++;
/* */
}
cout << endl; //
cout<<" : " << k << endl;
cout<<" : " << min<<endl;
cout<<"() : ";
ShowIndex(k, min);
// min
cout<<" : " << max <<endl;
cout<<"() : ";
ShowIndex(k, max);
// max
_getch();
return 0;
}
/* , k , , m, */
void ShowIndex(int k,float m)
{
file.clear();
file.seekg(0L,ios::beg); //
float n; // ,
for (int i=0; i<k; i++) // k
{
file>>n;
if (n == m) cout << i << ' ';
// m,
|
|
}
cout<<endl;
}
4. A[5][5] [-3, 3] , .
, , ; , : i + j = n+1, n .
#include<iostream>
#include<locale> //!!!
#include<iomanip>
#include<math.h>
#include<conio.h>
#include<String.h>
#include<ctype.h>
#include<stdlib.h>
#include<windows.h>
using namespace std;
int main()
{
if(SetConsoleCP(1251)==0)
{
cerr<<"Fialed to set codepage!"<<endl;
}
if(SetConsoleOutputCP(1251)==0)
{
cerr<<"Failed to set OUTPUT page!"<<endl;
}
// 2-
int n=5, **a= new int*[n];
cout<<" :\n";
int RANGE_MIN = -3; //
int RANGE_MAX = 7; //
//
for (int i = 0; i < 5; i++) //
{
a[i]=new int [n];
// :
for (int j = 0; j < 5; j++) // !
{
a[i][j]=(int)(((double) rand() / (double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
cout<< setw(5)<<a[i][j];
}
cout<<endl;
/* */
}
cout <<endl;
// :
long p = 1;
for (int i = 0; i < 5; i++)
p *= a[i][5-i-1]; //
// ,
cout << "\n , = " << p << endl;
_getch();
return 0;
}