Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handling -Hackerrank problem solution in C++ #61

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions C++/Cpp-exception-handling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<bits/stdc++.h>
using namespace std;

void process_input(int n);
int largest_proper_divisor(int n);

int main() {
int n;
cin >> n;
process_input(n);
return 0;
}


void process_input(int n) {
try {
int d = largest_proper_divisor(n);
cout << "result=" << d << endl;
} catch(exception &e) {
cout << e.what() << endl;
}
cout << "returning control flow to caller" << endl;
}

int largest_proper_divisor(int n) {
if (n == 0) {
throw invalid_argument("largest proper divisor is not defined for n=0");
}
if (n == 1) {
throw invalid_argument("largest proper divisor is not defined for n=1");
}
for (int i = n/2; i >= 1; --i) {
if (n % i == 0) {
return i;
}
}
return -1;
}
6 changes: 6 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
- Place: Islamabad, Pakistan
- Bio: Beta Microsoft Learn Student Ambassador | Co-Lead MLSA - Women Tech Hub
- GitHub: [Mahnoor26](https://github.com/mahnoor26)

#### Name: [Sakshi Rai](https://github.com/Sakshirai273)

- Place: India
- Bio: Google cloud facilitaor program contributor | Web developer
- Github: [Sakshirai273](https://github.com/Sakshirai273)
20 changes: 20 additions & 0 deletions profiles/Sakshirai273.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Sakshi Rai

### Location:
UP, India

### Academics:
Bachelor of Technology in Computer Science and information technology.

### Skills:
- Python
- React/Node JS
- C++
- JavaScript
- HTML/CSS

### Projects
- NA

### Profile
- [Sakshirai273](https://github.com/Sakshirai273)