#include<stdio.h>
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);
}
}
Enter a number to check prime or Not: 13
Number 13 is prime.
<hr>
Enter a number to check prime or Not: 15
Number 15 is not prime.
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.