about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/1/Bonus.c
blob: e98bee50deb936893f1e37ae87d82830ac5019b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * Read an integer from stdin and print its prime factors to stdout
 * This is free and unencumbered software released into the public domain.
 */

#include <stdio.h>

int main()
{
	unsigned n, m = 0;

	scanf("%u", &n);

	for (unsigned i = 2; i * i <= n; ++i)
		while (n % i == 0) {
			printf(m++ ? " %u" : "%u", i);
			n /= i;
		}
	if (n != 1)
		printf(m++ ? " %u" : "%u", n);
	if (m)
		putchar(10);

	return 0;
}