Skip to content

Instantly share code, notes, and snippets.

@YusufOzmen01
Created September 20, 2024 18:18
Show Gist options
  • Select an option

  • Save YusufOzmen01/180a6c62d984169bd6819a87eae8a8e0 to your computer and use it in GitHub Desktop.

Select an option

Save YusufOzmen01/180a6c62d984169bd6819a87eae8a8e0 to your computer and use it in GitHub Desktop.
#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