Last active
January 1, 2023 14:11
-
-
Save codepediair/97e21ac7015c8696881c402dc49290e2 to your computer and use it in GitHub Desktop.
why we use functions
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
#include <stdio.h> | |
int isPrime(int n){ | |
for (int i=2; i < n; i++){ | |
if (n % i == 0){ | |
return 0; | |
} | |
} | |
return 1; | |
} | |
int main() | |
{ | |
for (int i = 1000; i < 10000; i++){ | |
if (isPrime(i) == 1){ | |
printf("%d\n", i); | |
break; | |
} | |
} | |
// wrong | |
// printf("please enter a number :"); | |
// int n; | |
// scanf("%d", &n); | |
// int flag = 1; | |
// for (int i = 2; i < n; i++) | |
// { | |
// if (n % i == 0){ | |
// printf("%d is not prime\n" ,n); | |
// flag = 0; | |
// break; | |
// } | |
// } | |
// if (flag == 1){ | |
// printf("%d is prime\n", n); | |
// } | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment