C Program to Check Prime or Composite Number

Here we have a Python Program to Check whether the number entered by the user is a Prime Number or a Composite Number

A Prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.

Example C Program to Check for Prime or Composite Number

 1 #include<stdio.h>
 2 int main()
 3 {
 4      int number, counter, isprime = 0;
 5      printf("Enter the positive integer to check for prime or composite\n");
 6      scanf("%d",&number);
 7 
 8      for(counter = 2; counter <= number/2; counter++){
 9           if( (number % counter) == 0 ){
10                isprime = 1;
11                break;
12           }
13      }
14 
15      if(isprime == 0){
16         printf("%d is a prime number",number);
17      }else{
18         printf("%d is a composite number",number);
19      }
20 
21      return 0;
22 }

Watch this video to learn the step by step process of writing this program