Skip to content

Instantly share code, notes, and snippets.

@codepediair
Last active January 1, 2023 14:11
Show Gist options
  • Save codepediair/97e21ac7015c8696881c402dc49290e2 to your computer and use it in GitHub Desktop.
Save codepediair/97e21ac7015c8696881c402dc49290e2 to your computer and use it in GitHub Desktop.
why we use functions
#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