C language program to find prime number
- Get link
- X
- Other Apps
Hello every one today this post is about how to write a C language program to find weather an input number is prime or not. I hope you will learn alot from it and if you dont understand so you can contact with Through +923429327224. I have also some online paid cources but i will sell it to you in half price.
#include <stdio.h>
int main() {
int num, i, flag = 0;
printf("Enter a number: ");
scanf("%d", &num);
if (num <= 1) {
printf("%d is not a prime number.\n", num);
return 0;
}
for(i = 2; i <= num/2; ++i) {
if(num % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
printf("%d is a prime number.\n", num);
else
printf("%d is not a prime number.\n", num);
return 0;
}
- Get link
- X
- Other Apps
Comments
Very informative
ReplyDelete