Skip to content

Commit 887d264

Browse files
committed
Feat: Jason lesson_04 ReadMe
1 parent 0d42f88 commit 887d264

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

lesson_04/JasonWatson/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
## C
22

3-
```c
3+
```C
44
#include <stdio.h>
55
#include <stdbool.h>
66

77
bool isPrime(int n) {
88
if (n <= 1) return false;
9-
for (int i = 2; i <= sqrt(n); i++) {
9+
for (int i = 2; i * i <= n; i++) {
1010
if (n % i == 0) return false;
1111
}
1212
return true;
1313
}
1414

15-
nt main() {
15+
int main() {
1616
int number = 29;
1717
if (isPrime(number))
18-
printf("%d is a prime number . \n", )
18+
printf("%d is a prime number . \n", number );
19+
else
20+
printf("%d is not a prime number . \n", number );
1921
return 0;
2022
}
2123
```
@@ -43,13 +45,26 @@ isPrime(number) << std::end1;
4345
```
4446

4547
## Explanation
48+
This C program checks if a given nember is a prime number.It uses a function isPrime() to then determine whether a number is a prime number and the gives the output.
49+
50+
This C++ program checks when a given number is a prime number by using the simple function isPrime() and the gives an out. It does so by using the <iostream> which is a library for input/output and the <cmath> for calculation.
51+
52+
53+
### DIFFERENCES
54+
55+
1. **Syntax**:
56+
- In C it uses a standard input-output library which gives us the ability to use functions such as print() to give output.
57+
- In C++ it uses a standard input-output stream library which makes us be able to use std::cout and std::endl to display the output.
58+
59+
2. **How they carry out calculation**:
60+
- C uses the bool data type to which provides true and false values for logical operation whilst the C++ use a math library to do mathematical functions such as sqrt() that calculkates square root numbers.
4661

4762

4863

49-
### Differences
64+
### SIMILARITIES
5065

51-
1. **
66+
1. **Codes**:
67+
- Both C and C++ use the function if (n <= 1) return false to determine if the number is a prime number.
68+
- They both have the ability to do loop for Checking Divisibility.
69+
- the function return true; is use by both programs to return true if No Divisors found.
5270

53-
2. **
54-
55-
3. **

0 commit comments

Comments
 (0)