Created
January 23, 2023 13:24
-
-
Save pegvin/7568eff0c0ced0871c838d1ab7826bd5 to your computer and use it in GitHub Desktop.
Simple Function To Get A Single Digit From A Number At A Index
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 <stdlib.h> | |
#include <stdio.h> | |
int GetDigitAtIndex(int index, int num) { | |
int dig = 0, i = 0; | |
while(num > 0) { | |
dig = num % 10; | |
num = num / 10; | |
if (i == index) return dig; | |
i++; | |
} | |
return -1; | |
} | |
int main(void) { | |
int AppVersion = 364; | |
printf( | |
"Application Version %d.%d.%d\n", | |
GetDigitAtIndex(2, AppVersion), | |
GetDigitAtIndex(1, AppVersion), | |
GetDigitAtIndex(0, AppVersion) | |
); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment