C Program to check whether a given number is prime or not (using do-while loop)

C Programming Language / Loop control in C Language

6478

Program:

#include<stdio.h>
void main()
{

int number, i = 2;
int indicator =  0;
printf("Enter a number to check prime or Not: ");
scanf("%d",&number);

do{
	if(number%i == 0)
	{
	 indicator = 1;
	 break;
	}
 
 i++;
}while(i < number/2);

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. 

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.