Skip to content
This repository was archived by the owner on May 18, 2024. It is now read-only.

Commit da09967

Browse files
committed
first commit
0 parents  commit da09967

File tree

45 files changed

+1543
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1543
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore Everything
2+
*
3+
4+
# But not .cpp
5+
!*.cpp
6+
# Or directories
7+
!*/
8+
!.gitignore
9+
!README.md

2DArray/main.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <iostream>
2+
#include <ctime>
3+
4+
int main()
5+
{
6+
srand(time(NULL));
7+
8+
int row;
9+
int col;
10+
11+
std::cin >> row >> col;
12+
13+
int **arr = new int *[row];
14+
for (int i = 0; i < row; i++)
15+
{
16+
arr[i] = new int[col];
17+
}
18+
19+
for (int i = 0; i < row; i++)
20+
{
21+
for (int j = 0; j < col; j++)
22+
{
23+
arr[i][j] = rand() % 100 - 50;
24+
//std::cin >> arr[i][j];
25+
}
26+
}
27+
28+
for (int i = 0; i < row; i++)
29+
{
30+
for (int j = 0; j < col; j++)
31+
{
32+
//std::cout << arr[i][j] << " ";
33+
printf("%d ", arr[i][j]);
34+
}
35+
std::cout << std::endl;
36+
}
37+
38+
for (int i = 0; i < row; i++)
39+
{
40+
delete[] arr[i];
41+
}
42+
43+
delete[] arr;
44+
45+
for (int i = 0; i < row; i++)
46+
{
47+
for (int j = 0; j < col; j++)
48+
{
49+
std::cout << arr[i][j] << " ";
50+
//printf("%d ", arr[i][j]);
51+
}
52+
std::cout << std::endl;
53+
}
54+
55+
return 0;
56+
}

AverageSumArray/main.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
#include <ctime>
3+
4+
int main()
5+
{
6+
srand(time(NULL));
7+
8+
const int row = 3;
9+
const int col = 3;
10+
11+
int arr[row][col];
12+
double average[row] = {0.0};
13+
14+
for (int x = 0; x < row; x++)
15+
{
16+
for (int y = 0; y < col; y++)
17+
{
18+
arr[x][y] = rand() % 21;
19+
}
20+
}
21+
22+
for (int x = 0; x < row; x++)
23+
{
24+
for (int y = 0; y < col; y++)
25+
{
26+
std::cout << arr[x][y] << " ";
27+
}
28+
std::cout << std::endl;
29+
}
30+
31+
for (int x = 0; x < row; x++)
32+
{
33+
for (int y = 0; y < col; y++)
34+
{
35+
average[x] += arr[x][y];
36+
}
37+
average[x] = average[x] / (double)row;
38+
}
39+
40+
int max = average[0];
41+
int index;
42+
for (int i = 0; i < row; i++)
43+
{
44+
if (average[i] > max)
45+
{
46+
max = average[i];
47+
index = i;
48+
}
49+
}
50+
51+
for (int i = 0; i < row; i++)
52+
{
53+
std::cout << average[i] << " ";
54+
}
55+
56+
std::cout << std::endl << "Index = " << index;
57+
58+
return 0;
59+
}

Bin2Dec/main.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
#include <math.h>
3+
4+
int bin2dec(char str[])
5+
{
6+
int v = 0;
7+
int l = 0;
8+
while(str[l]) l++;
9+
for (int i = 0; str[i]; i++)
10+
{
11+
v += (str[i] - '0') << (l - i - 1);
12+
}
13+
return v;
14+
}
15+
16+
int main()
17+
{
18+
char str[] = "00001010";
19+
20+
std::cout << bin2dec(str);
21+
22+
return 0;
23+
}

BitsFunctions/main.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
3+
int onBit(unsigned int num, unsigned int n)
4+
{
5+
unsigned int m = 1 << n;
6+
num = num | m;
7+
return num;
8+
}
9+
10+
int offBit(unsigned int num, unsigned int n)
11+
{
12+
unsigned int m = 1 << n;
13+
m = ~m;
14+
return num & m;
15+
}
16+
17+
int reverse(unsigned int num, unsigned int n)
18+
{
19+
unsigned int m = 1 << n;
20+
num = num ^ m;
21+
return num;
22+
}
23+
24+
int main()
25+
{
26+
printf("%d\n", onBit(10, 0));
27+
printf("%d\n", offBit(10, 3));
28+
printf("%d", reverse(9, 0));
29+
30+
return 0;
31+
}

Blur/main.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <ctime>
4+
5+
void conv(double begin[][4], double end[][4], int row, int col)
6+
{
7+
for (int x = 0; x < row; x++)
8+
{
9+
for (int y = 0; y < col; y++)
10+
{
11+
end[x][y] = begin[x][y];
12+
if (x - 1 >= 0)
13+
{
14+
end[x][y] += begin[x - 1][y];
15+
}
16+
if (x + 1 < row)
17+
{
18+
end[x][y] += begin[x + 1][y];
19+
}
20+
if (y - 1 >= 0)
21+
{
22+
end[x][y] += begin[x][y - 1];
23+
}
24+
if (y + 1 < col)
25+
{
26+
end[x][y] += begin[x][y + 1];
27+
}
28+
end[x][y] /= 5;
29+
}
30+
}
31+
}
32+
33+
int main()
34+
{
35+
srand(time(NULL));
36+
37+
const int row = 4;
38+
const int col = 4;
39+
40+
double begin[row][col];
41+
double end[row][col] = {0};
42+
43+
for (int x = 0; x < row; x++)
44+
{
45+
for (int y = 0; y < col; y++)
46+
{
47+
begin[x][y] = rand() % 255;
48+
}
49+
}
50+
51+
for (int x = 0; x < row; x++)
52+
{
53+
for (int y = 0; y < col; y++)
54+
{
55+
printf("%.3f ", begin[x][y]);
56+
}
57+
printf("\n");
58+
}
59+
60+
printf("\n");
61+
62+
conv(begin, end, row, col);
63+
64+
for (int x = 0; x < row; x++)
65+
{
66+
for (int y = 0; y < col; y++)
67+
{
68+
printf("%.3f ", end[x][y]);
69+
}
70+
printf("\n");
71+
}
72+
73+
return 0;
74+
}

ConsoleApp/main.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <ctime>
4+
5+
int main()
6+
{
7+
std::cout << "Hello world";
8+
9+
return 0;
10+
}

CountWordsInString/main.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
3+
int fun(const char[]);
4+
5+
int main()
6+
{
7+
char str[] = "h ell oworld";
8+
9+
printf("words num = %d", fun(str));
10+
11+
return 0;
12+
}
13+
14+
int fun(const char str[])
15+
{
16+
int count = 0;
17+
for (int i = 0; str[i]; i++)
18+
{
19+
if (str[i] != ' ')
20+
{
21+
for (i;; i++)
22+
{
23+
if (str[i] == ' ')
24+
{
25+
break;
26+
}
27+
else if (str[i] == '\0')
28+
{
29+
i--;
30+
break;
31+
}
32+
}
33+
count++;
34+
}
35+
}
36+
return count;
37+
}

DoubleTroubles/main.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
#include <ctime>
3+
4+
double randomDouble(double, double);
5+
6+
int main()
7+
{
8+
srand(time(NULL));
9+
10+
for (int i = 0; i < 100; i++)
11+
{
12+
printf("%f\n", randomDouble(-5.0, 3.0));
13+
}
14+
15+
return 0;
16+
}
17+
18+
double randomDouble(double min, double max)
19+
{
20+
return min + ((double)rand() / RAND_MAX) * (max - min);
21+
}

Fib/main.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
3+
int fibIt(int);
4+
int fibRek(int);
5+
6+
int main()
7+
{
8+
unsigned int index;
9+
std::cin >> index;
10+
11+
printf("%d\n", fibIt(index));
12+
printf("%d", fibRek(index));
13+
return 0;
14+
}
15+
16+
int fibRek(int idx)
17+
{
18+
if (idx == 0)
19+
{
20+
return 0;
21+
}
22+
if (idx < 3)
23+
{
24+
return 1;
25+
}
26+
return fibRek(idx - 1) + fibRek(idx - 2);
27+
}
28+
29+
int fibIt(int idx)
30+
{
31+
int n1 = 0;
32+
int n2 = 1;
33+
int n3;
34+
if (idx == 1)
35+
return n1;
36+
for (int i = 1; i < idx - 1; i++)
37+
{
38+
n3 = n1 + n2;
39+
n1 = n2;
40+
n2 = n3;
41+
}
42+
return n3;
43+
}

0 commit comments

Comments
 (0)