SVN / public / code / vorlesung-02 / Prime.cpp

Revision 997
Date2026-04-28T16:11:40+02:00
Committerhb1003
Download
// Copyright 2026, University of Freiburg
// Chair of Algorithms and Data Structures
// Author: Hannah Bast <bast@cs.uni-freiburg.de>

#include "./Prime.h"

// ____________________________________________________________________________
int isPrime(int n) {
  if (n <= 1) {
    return 1;
  }
  int i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      return i;
    }
    i = i + 1;
  }
  return 0;
}