Skip to content

Commit

Permalink
add others
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniilVdovin committed May 22, 2023
1 parent f31bfff commit e5cfa15
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/Dynamic arrays/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
bool simpl(int* n) {
for (int i = 2; i <= sqrt(*n); i++)
if (*n % i == 0) return false;
return true;
}
int main() {
int N,Size=0,j=0;
cin >> N;
for (int i = 2; i < N; i++)if(simpl(&i))Size++;
int* array = new int[Size];
for (int i = 2; i < N; i++) {
if (simpl(&i)) {
array[j] = i;
cout << array[j] << ' '; j++;
}
}
delete(array);
return 0;
}
/*
5 = 2 3
10 = 2 3 5 7
20 = 2 3 5 7 11 13 17 19
*/
22 changes: 22 additions & 0 deletions Source/Dynamic arrays/11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int main() {
int n,rs=0,i=0;
cin >> n;
int *N { (int*)calloc(n , sizeof(int)) },
*RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 1; i < n; ++i){
if (N[i] > N[i-1]) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(RS);
return 0;
}
/*
5 1 2 3 2 1 = 2 3
5 1 2 3 2 3 = 2 3 3
7 7 5 6 1 3 4 5 = 6 3 4 5
*/
41 changes: 41 additions & 0 deletions Source/Dynamic arrays/12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
using namespace std;
int MaxIndex(int* Ar,int n) {
int mv = 0, mi = 0;
for (int i = 0; i < n; i++){
if (mv < Ar[i]) {
mv = Ar[i]; mi = i;
}}
return mi;
}
int MinIndex(int* Ar, int n) {
int mv = 1000, mi = 0;
for (int i = 0; i < n; i++) {
if (mv > Ar[i]) {
mv = Ar[i]; mi = i;
}}
return mi;
}
int main() {
int n, m, rs = 0, i = 0;
cin >> n >> m;
int * N { (int*)calloc(n , sizeof(int)) },
* M { (int*)calloc(m , sizeof(int)) },
* RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < m; ++i) cin >> M[i];
for (i = 0; i < MinIndex(N,n); ++i) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i]; }
for (i = MaxIndex(M, m) + 1; i < m; ++i) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = M[i]; }
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(M); free(RS);
return 0;
}
/*
3 3 3 2 1 3 2 1 = 3 2 2 1
4 4 2 5 4 6 9 5 8 7 = 5 8 7
2 2 1 2 2 1 = 1
*/
17 changes: 17 additions & 0 deletions Source/Dynamic arrays/13.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
using namespace std;
int main() {
int n, i = 0;
cin >> n;
int* N{ (int*)calloc(n , sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < n; ++i) N[i]*=-1;
for (i = 0; i < n; i++) cout << N[i] << ' ';
free(N);
return 0;
}
/*
5 1 -2 3 -4 5 = -1 2 -3 4 -5
6 -1 -2 -0 5 3 -9 = 1 2 0 -5 -3 9
2 0 -0 = 0 0
*/
29 changes: 29 additions & 0 deletions Source/Dynamic arrays/14.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
int main() {
int n, m, rs = 0, i = 0;
cin >> n >> m;
int* N{ (int*)calloc(n , sizeof(int)) },
* M{ (int*)calloc(m , sizeof(int)) },
* RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) {
cin >> N[i];
if (N[i] > 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < m; ++i) {
cin >> M[i];
if (M[i] < 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = M[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(M); free(RS);
return 0;
}
/*
4 4 5 -4 2 -2 -1 2 -3 4 = 5 2 -1 -3
2 2 -1 2 -2 1 = 2 -2
2 2 -1 1 1 -1 = 1 -1
*/
24 changes: 24 additions & 0 deletions Source/Dynamic arrays/14_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
int main() {
int n, m, rs = 0, i = 0;
cin >> n >> m;
int* N{ (int*)calloc(n , sizeof(int)) },
* M{ (int*)calloc(m , sizeof(int)) },
* RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) {
N[i] = int((-100 + rand()/100));
if (N[i] > 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < m; ++i) {
M[i] = int((-100 + rand()/100));
if (M[i] < 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = M[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(M); free(RS);
return 0;
}
27 changes: 27 additions & 0 deletions Source/Dynamic arrays/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;
int main() {
int n, d{ 2 }, k{ 4 },s=0;
cin >> n;
int* rs{(int*)calloc(s, sizeof(int))};
while (k <= n)
{
while (n%d == 0)
{
s++;
rs = (int*)realloc(rs,(s+1)*sizeof(int));
rs[s-1] = d;
n /= d;
}
k += 2 * d + 1; d += 1;
}
rs[s] = n;
for (int i = 0; i <= s; i++) cout << rs[i] << ' ';
free(rs);
return 0;
}
/*
6 = 2 3
66 = 2 3 11
132 = 2 2 3 11
*/
19 changes: 19 additions & 0 deletions Source/Dynamic arrays/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int Fib(int n) {
return n == 1 || n == 2 ? 1 : Fib(n - 1) + Fib(n - 2);
}
int main() {
int n;
cin >> n;
int* rs{ (int*)calloc(n, sizeof(int)) };
for (int i = 1; i <= n; ++i) rs[i] = Fib(i);
for (int i = 0; i <= n; i++) cout << rs[i] << ' ';
free(rs);
return 0;
}
/*
5 = 0 1 1 2 3 5
10 = 0 1 1 2 3 5 8 13 21 34 55
15 = 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
*/
29 changes: 29 additions & 0 deletions Source/Dynamic arrays/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
int main() {
int n, m,rs=0,i=0;
cin >> n >> m;
int *N { (int*)calloc(n , sizeof(int)) },
*M { (int*)calloc(m , sizeof(int)) },
*RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < m; ++i) cin >> M[i];
for (i = 0; i < n; ++i){
if (N[i] > 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < m; ++i) {
if (M[i] > 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = M[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(M); free(RS);
return 0;
}
/*
2 2 -1 -3 5 1 = 5 1
2 2 -1 5 3 -5 = 5 3
4 2 1 2 -3 4 -1 -2 = 1 2 4
*/
29 changes: 29 additions & 0 deletions Source/Dynamic arrays/6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
int main() {
int n, m,rs=0,i=0;
cin >> n >> m;
int *N { (int*)calloc(n , sizeof(int)) },
*M { (int*)calloc(m , sizeof(int)) },
*RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < m; ++i) cin >> M[i];
for (i = 0; i < n; ++i){
if (N[i] % 2 == 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < m; ++i) {
if (M[i] % 2 == 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = M[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(M); free(RS);
return 0;
}
/*
2 2 2 4 5 1 = 2 4
2 3 1 2 5 6 8 = 2 6 8
4 2 1 2 3 4 9 6 = 2 4 6
*/
22 changes: 22 additions & 0 deletions Source/Dynamic arrays/7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int main() {
int n,rs=0,i=0;
cin >> n;
int *N { (int*)calloc(n , sizeof(int)) },
*RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < n; ++i){
if (N[i] > 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(RS);
return 0;
}
/*
3 -1 -2 3 = 3
4 -2 -10 1 55 = 1 55
4 2 10 -1 -55 = 2 10
*/
22 changes: 22 additions & 0 deletions Source/Dynamic arrays/8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int main() {
int n,rs=0,i=0;
cin >> n;
int *N { (int*)calloc(n , sizeof(int)) },
*RS{ (int*)calloc(rs, sizeof(int)) };
for (i = 0; i < n; ++i) cin >> N[i];
for (i = 0; i < n; ++i){
if (N[i] < 0) {
rs++; RS = (int*)realloc(RS, rs * sizeof(int));
RS[rs - 1] = N[i];
}}
for (i = 0; i < rs; i++) cout << RS[i] << ' ';
free(N); free(RS);
return 0;
}
/*
3 -1 -2 3 = -1 -2
4 -2 -10 1 55 = -2 -10
4 2 10 -1 -55 = -1 -55
*/
15 changes: 15 additions & 0 deletions Source/Pointers/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>
#include <math.h>
using namespace std;
void fun(float* Perimeter, float* Square, float* Side1, float* Side2, float* Side3) {
*Perimeter = *Side1 + *Side2 + *Side3;
*Square = sqrtf(*Perimeter/2 * (*Perimeter/2 - *Side1) * (*Perimeter/2 - *Side2) * (*Perimeter/2 - *Side3));
}
int main() {
float Perimeter, Square, Side1, Side2, Side3;
cin >> Side1 >> Side2 >> Side3;
fun(&Perimeter, &Square, &Side1, &Side2, &Side3);
cout.precision(2);
cout << fixed << endl << Perimeter << " " << Square << endl;
return 0;
}
16 changes: 16 additions & 0 deletions Source/Pointers/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
void fun(float* Perimeter, float* Square, float* Radius) {
*Perimeter = 2 * M_PI * *Radius;
*Square = M_PI*powf(*Radius,2.0);
}
int main() {
float Perimeter, Square, Radius;
cin >> Radius;
fun(&Perimeter, &Square, &Radius);
cout.precision(2);
cout << fixed << endl << Perimeter << " " << Square << endl;
return 0;
}
16 changes: 16 additions & 0 deletions Source/Pointers/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
void fun(float* A, float* B, float* Side1, float* Side2) {
*B = (atanf(*Side2 / *Side1)*180)/M_PI;
*A = 90 - *B;
}
int main() {
float A, B, Side1, Side2;
cin >> Side1 >> Side2;
fun(&A, &B, &Side1,&Side2);
cout.precision(2);
cout << fixed << endl << A << " " << B << " " << 90.00 << endl;
return 0;
}
Loading

0 comments on commit e5cfa15

Please sign in to comment.