- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main() //головна функція
- •Int main()
- •Int main() //головна функція
- •Int main()
- •Int main()
- •Int main()
- •Int main() //головна функція
- •Int main()
- •Int main()
- •Int main() //головна функція
- •Int main()
- •Int main()
- •Int main ()
- •Int main()
- •Int main ()
- •Int main()
- •Int main ()
- •Int main()
- •Int main()
- •Int main ()
- •Int main ()
- •Int main ()
- •Int main ()
- •Int main ()
- •Int main ()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Void main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Void main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
- •Int main()
Int main()
{
int k;
cout<<"Input number of rows and columns <= 5"<<endl;
cin>>n>>m;
input();
cout<<"Matrix before delete row"<<endl;
output();
cout<<"Input number of row to delete"<<endl;
cin>>k;
for (int i=k; i<n-1; i++)
for (int j=0; j<m; j++)
a[i][j]=a[i+1][j];
n--;
cout<<"Matrix after delete row"<<endl;
output();
system("pause");
}
Приклад 7.17
/* Множення матриць */
#include <iostream>
using namespace std;
typedef float Matrix[10][10];
int i,j;
Matrix A,B;
Matrix C;
int row1,row2;
int col1,col2;
//====================== Функція введення матриці ====================
void input(Matrix Mas, int& line, int& kol)
{
do
{
cout<<"Input numbers of rows >=1 ";
cin>>line;
cout<<"Input numbers of columns >=1 ";
cin>>kol;
if ((line<1) || (kol<1))
cout<<"It's few, input more"<<endl;
}
while ((line<=1) && (kol<=1));
cout<<"Input matrix: "<<endl;
for (int i=0; i<line; i++)
for (int j=0; j<kol; j++)
cin>>Mas[i][j];
}
//==================== процедура виведення матриці =================
void output(Matrix Mas, int line, int kol)
{
for (int i=0; i<line; i++)
{
for (int j=0; j<kol; j++)
cout<<Mas[i][j]<<" ";
cout<<endl;
}
}
//=========================== множення матриць ======================
void mult()
{
int k;
if (col1!=row2)
cout<<"Multiplication is impossible - matrix are unconformable"<<endl;
else
{
for (int i=0; i<row1; i++)
for (int j=0; j<col2; j++)
{
C[i][j]=0;
for (k=0; k<col1; k++)
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
}
}
//========================== головна функція ==============================
Int main()
{
cout<<"Input matrix A: "<<endl;
input(A,row1,col1);
cout<<"Input matrix B: "<<endl;
input(B,row2,col2);
cout<<"Matrix A: "<<endl;
output(A,row1,col1);
cout<<"Matrix B: "<<endl;
output(B,row2,col2);
mult();
cout<<"Result of multiplication: "<<endl;
output(C,row1,col2);
system("pause");
}
Приклад 7.18
/* Обчислити визначник матриці */
#include <iomanip>
#include <iostream>
using namespace std;
float det;
int n;
float a[5][5];
int sign;
//============= введення елементів матриці ====================
void input()
{
cout<<"Input size of matrix"<<endl;
cin>>n;
cout<<"Input components of matrix"<<endl;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}
}
//============= виведення значень елементів матриці ============
void output()
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cout<<fixed;
cout<<setw(10)<<setprecision(2)<<a[i][j]<<" ";
}
cout<<endl;
}
}
//=============== обчислення трикутної матриці ====================
void triangular(int k)
{
float koef;
for (int l=k+1; l<n; l++)
{
koef=a[l][k]/a[k][k];
for(int j=0; j<n; j++)
a[l][j]-=a[k][j]*koef;
}
}
//======================= перестановка рядків ======================
void change(int row)
{
float tmp;
sign=1;
for (int j=0; j<n-row; j++)
if (a[row+j][row]!=0)
{
for (int k=0; k<n; k++)
{
tmp=a[row][k];
a[row][k]=a[row+j][k];
a[row+j][k]=tmp;
}
sign=-sign;
}
}
//======================== обчислити визначник ========================
void determinant()
{
for (int i=0; i<n; i++)
{
if (a[i][i]==0)
change(i);
triangular(i);
}
det=1;
for (int i=0; i<n; i++)
det*=a[i][i];
if (sign<0) det=-det;
}
//================= головна функція ========================
int main()
{
cout<<"Determinant of matrix"<<endl;
input();
cout<<"Initial matrix"<<endl;
output();
determinant();
cout<<"Triangular matrix"<<endl;
output();
cout<<"det="<<det<<endl;
system("pause");
}
Приклад 8.2
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char congratulation [50];
puts("Enter congratulation");
gets(congratulation);
cout<<"length="<<strlen(congratulation)<<endl;
congratulation[15]='\0';
cout<<congratulation<<endl;
}
Приклад 8.3
#include <stdio.h>
#include <string.h>
int main()
{
char s[11]="Visual C++";
char newstr[5];
strcpy(newstr,s);
puts(newstr);
}
Приклад 8.4
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char s1[11]="Visual C++";
char s2[]="Visual Studio";
char* s3[]="Visual Studio";
cout<<strcmp(s1,s2)<<" "<<strcmp(s2,s3)<<" "<<strcmp(s3,s1)<<endl;
}
Приклад 8.5
/* Демонстрація конкaтeнації рядків */
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char name[5];
char address[13];
char str1[7];
char str2[255];
puts("Enter name");
gets(name);
cout<<"Length of name="<<strlen(name)<<endl;
puts("Enter address");
gets(address);
cout<<"Length of address="<<strlen(address)<<endl;
strcpy(str1,name);
strcat(str1,address);
puts(str1);
cout<<"Length of str1="<<strlen(str1)<<endl;
strcpy(str2,name);
strcat(str2,address);
puts(str2);
cout<<"Length of str2="<<strlen(str2)<<endl;
system("pause");
}
Приклад 8.6
/* Пошук та заміна символів у рядку */
#include <iostream>
#include <string.h>
using namespace std;
