Skip to content

Instantly share code, notes, and snippets.

@danhper
Created July 18, 2013 02:42
Show Gist options
  • Save danhper/6026317 to your computer and use it in GitHub Desktop.
Save danhper/6026317 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(void)
{
int a, i = 2;
printf("enter num: ");
scanf("%d", &a);
printf("%d = ", a);
while(a > 1) {
int n = 0;
while(a % i != 0) {
i++;
}
while(a % i == 0) {
a /= i;
n++;
}
if(n > 1) {
printf("%d^%d", i, n);
} else {
printf("%d", i, n);
}
if(a > 1) {
printf(" x ");
}
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment