write a C Program to check if the user given input number is a Prime Number or not

Filed in C Program Examples 0 comments

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:

  1. Properties of Exponentials
  2. fixing [ERROR] /usr/libexec/mysqld: Can’t create/write to file ‘/var/run/mysqld/mysqld.pid’ (Errcode: 13)
Posted by voshka   @   25 March 2011 0 comments

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Previous Post
«
Next Post
»
CrossBlock designed by DeltaManual.Com  |  In conjunction with Web Hosting   |   Web Hosting   |   Reverse phone