Skip to content

Commit 566fe70

Browse files
feat: adds Rashaad's code samples (#146)
* Create RM_README.md Creates folder for lesson 04 * feat: RM_README.md_lesson_04 Lesson_04 completed using "C#" and "C++". * typo
1 parent a452230 commit 566fe70

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

lesson_04/rasheedmiller/RM_README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## C# Implementation
2+
3+
```c#
4+
using System;
5+
6+
class Program
7+
{
8+
static bool IsPrime(int number)
9+
{
10+
if (number < 2)
11+
return false;
12+
13+
for (int i = 2; i <= Math.Sqrt(number); i++)
14+
{
15+
if (number % i == 0)
16+
return false;
17+
}
18+
return true;
19+
}
20+
21+
static void Main()
22+
{
23+
Console.Write("Enter a number: ");
24+
int num = int.Parse(Console.ReadLine());
25+
26+
if (IsPrime(num))
27+
Console.WriteLine($"{num} is a prime number.");
28+
else
29+
Console.WriteLine($"{num} is not a prime number.");
30+
}
31+
}
32+
```
33+
34+
## C++ Implementation
35+
36+
```c++
37+
#include <iostream>
38+
#include <cmath>
39+
40+
bool isPrime(int number) {
41+
if (number < 2)
42+
return false;
43+
44+
for (int i = 2; i <= std::sqrt(number); i++) {
45+
if (number % i == 0)
46+
return false;
47+
}
48+
return true;
49+
}
50+
51+
int main() {
52+
int num;
53+
std::cout << "Enter a number: ";
54+
std::cin >> num;
55+
56+
if (isPrime(num))
57+
std::cout << num << " is a prime number." << std::endl;
58+
else
59+
std::cout << num << " is not a prime number." << std::endl;
60+
61+
return 0;
62+
}
63+
```
64+
65+
## Explanation
66+
67+
The C# "C Sharp" implementation uses a function named `Is_Prime`. This function takes a `number` as input and reads `true` if the number is Prime or `false` if the number is not Prime.
68+
69+
The C++ "C Plus Plus" implementation uses a function named `is_Prime`. This function also takes a `number` as input and reads `true` if the number is Prime or `false` if the number is not Prime.
70+
71+
# Similarities and Differences Index Chart
72+
73+
| Feature | Similarities | Differences |
74+
|-----------------------|-----------------------------------------------|-----------------------------------------------|
75+
| **Syntax** | The names of the functions are similar. | C# uses "IsPrime". C++ uses "isPrime". |
76+
| **Input** | Both take user input. | One coded in C# language. One coded C++ language.|
77+
| **Main Function** | Both have main functions. | C# uses "static void Main()" C++ uses "int main()"|
78+
| **First Line of Code** | Both have a line of code to start. | C# starts with "using System;". C++ starts with "#include <iostream>"|
79+
| **Printing Output** | Both use printing outputs. | C# uses "Console.WriteLine()". C++ uses "std::cout <<". |
80+

0 commit comments

Comments
 (0)