Skip to content

Commit d1da8bb

Browse files
committed
chore: added c++ explanation
1 parent f684686 commit d1da8bb

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

lesson_04/evanphilakhong/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Evan Philakhong
2+
3+
## C++ implementation
4+
5+
#### main.hpp
6+
```c++
7+
#include <iostream>
8+
#include <string>
9+
using namespace std;
10+
11+
// function definition
12+
bool isPrime(int num);
13+
```
14+
#### main.cpp
15+
```c++
16+
bool isPrime(int num) {
17+
int count = 0;
18+
for (int i = num; i > 0; i--) {
19+
if (num%i == 0) {
20+
count++;
21+
}
22+
}
23+
if (count == 2) {
24+
cout << "This is a Prime Number" << endl;
25+
return true;
26+
}
27+
cout << "This is not a Prime Number" << endl;
28+
return false;
29+
}
30+
```
31+
32+
## Java implementation
33+
34+
```java
35+
public static boolean isPrime(int num) {
36+
int count = 0;
37+
for (int i = num; i > 0; i--) {
38+
if (num%i == 0) {
39+
count++;
40+
}
41+
}
42+
if (count == 2) {
43+
System.out.println("This is a Prime Number");
44+
return true;
45+
}
46+
System.out.println("This is not a Prime Number");
47+
return false;
48+
}
49+
```
50+
51+
## Explanation
52+
53+
The C++ implementation is using a function named `isPrime` that takes a single parameter `num` representing the number the function is checking if it's a prime number or not. The function returns `True` if the number is **Prime**

lesson_04/evanphilakhong/c++/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "header.hpp"
1+
#include "main.hpp"
22

33
bool isPrime(int num) {
44
int count = 0;

lesson_04/evanphilakhong/c++/header.hpp renamed to lesson_04/evanphilakhong/c++/main.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <iostream>
2-
#include <string>
32
using namespace std;
43

54
// function definition

0 commit comments

Comments
 (0)