From 0887d8f96950a060a122e14ed2981182ff1eb37d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 28 Dec 2019 21:16:58 +0700 Subject: [usth/ICT2.1] Algorithm and Data Structures --- usth/ICT2.1/labwork/1/Bonus.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 usth/ICT2.1/labwork/1/Bonus.c (limited to 'usth/ICT2.1/labwork/1/Bonus.c') diff --git a/usth/ICT2.1/labwork/1/Bonus.c b/usth/ICT2.1/labwork/1/Bonus.c new file mode 100644 index 0000000..e98bee5 --- /dev/null +++ b/usth/ICT2.1/labwork/1/Bonus.c @@ -0,0 +1,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 + +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; +} -- cgit 1.4.1