Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int sum(int n) {
- if (n < 0) {
- return -1;
- }
- else {
- if (n < 10) {
- if (n % 2 != 0) {
- return n;
- }
- else {
- return 0;
- }
- }
- else {
- if ((n % 10) % 2 != 0) {
- return n % 10 + sum(n / 10);
- }
- else {
- return sum(n / 10);
- }
- }
- }
- }
- void main() {
- cout << sum(-21313213);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement