Saturday, 5 September 2015

C Programme to find Weather a Number is prime or not


There are enough numbers out there in mathematics. Well, prime numbers are numbers in which they have only two factors(A number which can divide another number without any remainder) The number itself and 1. Lets find out how we can make a program to find weather a number is prime or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,flag;
clrscr();
printf("================================\n\n");
printf("Finding if a Number is Prime or Not\n\n");
printf("================================\n\n");
printf("Enter a Number\n");
scanf("%d",&n);
for(i=2;i<n/2;i++)
 {
  if(n%i==0)
  {
    flag=0;
    break;
  }
 }

if(flag==0)
 printf("Number is not prime");
else
 printf("Number is prime");
getch();
}


This programme will read a number from user and spit out weather the number is prime or not.



Download Wordpress Themes
http://themeforest.net/?ref=ppshobi

No comments:

Post a Comment