Friday, 26 November 2010

Write a C program in ‘c’ to find given positive number is prime number or not.

Write a C program in ‘c’ to find given positive number is prime number or not. 

Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
int I,n;
int ctr=0;
printf(“enter any no\n”);
scanf(“%d”&n);
for(i=1;<=n;i++)
{
if(n%i==0)
{
ctr++;
}
}
if(ctr==2)
{
printf(“%d is prime no\n”);
}
else
{
printf(“%d is not a prime no\n”);
}
getch();


No comments:

Post a Comment