diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6532339 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: cl.exe build active file", + "command": "cl.exe", + "args": [ + "/Zi", + "/EHsc", + "/nologo", + "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", + "${file}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$msCompile" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/PS-Sprint-1/1_even_odd_numbers.cpp b/PS-Sprint-1/1_even_odd_numbers.cpp new file mode 100644 index 0000000..3f4a649 --- /dev/null +++ b/PS-Sprint-1/1_even_odd_numbers.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() { + int n; + + cout << "Enter an integer: "; + cin >> n; + + if ( n % 2 == 0) + cout << n << " is even."; + else + cout << n << " is odd."; + + return 0; +} diff --git a/PS-Sprint-1/1_even_odd_numbers.exe b/PS-Sprint-1/1_even_odd_numbers.exe new file mode 100644 index 0000000..c911568 Binary files /dev/null and b/PS-Sprint-1/1_even_odd_numbers.exe differ diff --git a/PS-Sprint-1/2_checking_for_prime_numbers.cpp b/PS-Sprint-1/2_checking_for_prime_numbers.cpp new file mode 100644 index 0000000..d585fe4 --- /dev/null +++ b/PS-Sprint-1/2_checking_for_prime_numbers.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main() { + + int i, n; + bool is_prime = true; + + cout << "Enter a positive integer: "; + cin >> n; + + // 0 and 1 are not prime numbers + if (n == 0 || n == 1) { + is_prime = false; + } + + // loop to check if n is prime + for (i = 2; i <= n/2; ++i) { + if (n % i == 0) { + is_prime = false; + break; + } + } + + if (is_prime) + cout << n << " is a prime number"; + else + cout << n << " is not a prime number"; + + return 0; +} diff --git a/PS-Sprint-1/2_checking_for_prime_numbers.exe b/PS-Sprint-1/2_checking_for_prime_numbers.exe new file mode 100644 index 0000000..c769361 Binary files /dev/null and b/PS-Sprint-1/2_checking_for_prime_numbers.exe differ diff --git a/PS-Sprint-1/3_validating_leap_years.cpp b/PS-Sprint-1/3_validating_leap_years.cpp new file mode 100644 index 0000000..a1764da --- /dev/null +++ b/PS-Sprint-1/3_validating_leap_years.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main() +{ + int year; + + cout<<"Enter a year \n"; + cin>>year; + + if(year % 400 == 0) + cout << year << " is a Leap Year"; + + else if(year % 4 == 0 && year % 100 != 0) + cout << year << " is a Leap Year"; + + else + cout << year << " is not a Leap Year"; + + return 0; +} \ No newline at end of file diff --git a/PS-Sprint-1/3_validating_leap_years.exe b/PS-Sprint-1/3_validating_leap_years.exe new file mode 100644 index 0000000..57d5720 Binary files /dev/null and b/PS-Sprint-1/3_validating_leap_years.exe differ diff --git a/PS-Sprint-1/4_calculating_armstrong_numbers.cpp b/PS-Sprint-1/4_calculating_armstrong_numbers.cpp new file mode 100644 index 0000000..fe04a55 --- /dev/null +++ b/PS-Sprint-1/4_calculating_armstrong_numbers.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int main() { + int num, originalNum, remainder, result = 0; + cout << "Enter a three-digit integer: "; + cin >> num; + originalNum = num; + + while (originalNum != 0) { + // remainder contains the last digit + remainder = originalNum % 10; + + result += remainder * remainder * remainder; + + // removing last digit from the original number + originalNum /= 10; + } + + if (result == num) + cout << num << " is an Armstrong number."; + else + cout << num << " is not an Armstrong number."; + + return 0; +} \ No newline at end of file diff --git a/PS-Sprint-1/4_calculating_armstrong_numbers.exe b/PS-Sprint-1/4_calculating_armstrong_numbers.exe new file mode 100644 index 0000000..c5b2293 Binary files /dev/null and b/PS-Sprint-1/4_calculating_armstrong_numbers.exe differ diff --git a/PS-Sprint-1/5_fibonacci_series.cpp b/PS-Sprint-1/5_fibonacci_series.cpp new file mode 100644 index 0000000..2f62cb6 --- /dev/null +++ b/PS-Sprint-1/5_fibonacci_series.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int main() { + int t1 = 0, t2 = 1, nextTerm = 0, n; + + cout << "Enter a positive number: "; + cin >> n; + + // displays the first two terms which is always 0 and 1 + cout << "Fibonacci Series: " << t1 << ", " << t2 << ", "; + + nextTerm = t1 + t2; + + while(nextTerm <= n) { + cout << nextTerm << ", "; + t1 = t2; + t2 = nextTerm; + nextTerm = t1 + t2; + } + return 0; +} diff --git a/PS-Sprint-1/5_fibonacci_series.exe b/PS-Sprint-1/5_fibonacci_series.exe new file mode 100644 index 0000000..258e4c8 Binary files /dev/null and b/PS-Sprint-1/5_fibonacci_series.exe differ