Revision 154
Date2026-04-21T15:58:54+02:00
Committerhb1003
Download
| // Copyright 2026, University of Freiburg
// Chair of Algorithms and Data Structures
// Author: Hannah Bast <bast@cs.uni-freiburg.de>
#include <cstdio>
#include <cstdlib>
#include "./Prime.cpp"
// Main function.
int main(int argc, char **argv) {
// Parse command-line arguments.
if (argc != 2) {
printf("Usage: ./Prime <number>\n");
exit(1);
}
int n = atoi(argv[1]);
// If the number is prime, say so, otherwise output the smallest divisor
// greater than 1.
int i = isPrime(n);
if (i == 0) {
printf("Congratulations, %d is prime!\n", n);
} else {
printf("I am very sorry, %d is not prime; as a consolation, "
"here is the smallest non-trivial divisor: %d\n",
n, i);
}
}
|