Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int main() {
- double m;
- int n,i;
- printf("Podaj liczbe naturalna: ");
- scanf("%d", &n);
- if (n < 0)
- {
- printf("Podales zla liczbe");
- return 0;
- }
- m = sqrt(n);
- i = 3;
- if (n != 2 && n % 2 == 0 || n < 2)
- i = n;
- while (i < m)
- {
- if (n % i == 0)
- {
- i = n;
- }
- else
- {
- i += 2;
- }
- }
- if (i == n)
- {
- printf("%d nie jest liczba pierwsza", n);
- }
- else {
- printf("%d nie jest liczba pierwsza", n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement