-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c39fed0
commit 07fdbda
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.5.0 <0.9.0; | ||
//A prime number is a whole number greater than 1. It has exactly two factors, that is, 1 and the number itself. | ||
contract Day3 { | ||
//Create a function prime(uint n) . This prime() will check whether n is a prime number or not. | ||
function prime(uint256 n) public pure returns (uint256) { | ||
//If n is a prime number then prime() returns 1 and n is not prime then prime() must return 0. | ||
if (n <= 1) { | ||
return 0; //not prime | ||
} | ||
for (uint256 i = 2; i < n; i++) { | ||
if (n % i == 0) { | ||
return 0; //not prime | ||
} | ||
} | ||
return 1; //prime | ||
} | ||
} |