A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors 1 and itself.
3, 5, 7, 9, 13 are prime nubmers
forexample:
number 3 has only divisors of 1 and 3
5 is also dividable with only with 2 numbers 1 and 5
So lets get started creating a program to check if the input number is prime or not
#include <stdio.h>
#include <conio.h>
void main
(){
int input_num
;
int i
;
int counter
=0;
int divisors
= 0;
scanf("%d",&input_num
);
for(i
=2;i
<=input_num
;i
++)
{
if(!(input_num
% i
))
{
divisors
++;
}
}
if(divisors
==1)
{
printf("THis number has only one %d divisors so that \n",divisors
);
printf("%d is a prime number",input_num
);
}else{
printf("%d is not a prime number",input_num
);
}
getch();
}
Related posts:
- Properties of Exponentials
- fixing [ERROR] /usr/libexec/mysqld: Can’t create/write to file ‘/var/run/mysqld/mysqld.pid’ (Errcode: 13)