Created
September 20, 2024 18:18
-
-
Save YusufOzmen01/180a6c62d984169bd6819a87eae8a8e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdio.h> | |
| #include <stdlib.h> | |
| int power(int n, int p) { | |
| int out = n; | |
| for (int i = 1; i < p; i++) { | |
| out *= n; | |
| } | |
| if (p == 0) return 1; | |
| return out; | |
| } | |
| int main() { | |
| int num = 5432; | |
| char str[256]; | |
| int digits = 0; | |
| while (num / power(10, digits) >= 10) digits++; | |
| int i = 0; | |
| digits++; // increment the digits by one more to account for the last digit | |
| while (digits > 0) { | |
| if (i > 255) break; | |
| str[i] = (num / power(10, digits-1) - (num / power(10, digits)) * 10) + 48; | |
| digits--; i++; | |
| } | |
| printf("Num: %s\n", str); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment