Created
November 3, 2021 03:13
-
-
Save Sanokei/2594a4b5af5ea3016249bd95f01648d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
//using a recursive function get the first even digit in the number from all the individual digits in the number | |
int firstEven(int num){ | |
if(num < 10){ | |
if(num % 2 == 0){ | |
return num; | |
} | |
else{ | |
return 0; | |
} | |
} | |
else{ | |
if(num % 2 == 0){ | |
return num % 10; | |
} | |
else{ | |
return firstEven(num/10); | |
} | |
} | |
} | |
int main(){ | |
int num; | |
cout << "Enter a number: "; | |
cin >> num; | |
cout << "The first even digit in the number is: " << firstEven(num) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment