Check whether a given number is prime or not (using for loop)
C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)
943Program:
#include void main() { int number, i; int indicator = 0; printf("Enter a number to check prime or Not: "); scanf("%d",&number); for(i = 2; i < number/2; i++) { if(number%i == 0) { indicator = 1; break; } } if(indicator == 1){ printf(" \n Number %d is not prime. \n", number); } else{ printf(" \n Number %d is prime. \n", number); } }
Output:
Enter a number to check prime or Not: 13 Number 13 is prime.
Enter a number to check prime or Not: 15 Number 15 is not prime.
Explanation:
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.