Monday, 14 September 2015

Programming in C to find the given number is either prime or composite with limitation

#include<stdio.h>
#include<conio.h>
main()
{
int n=1,l,a=2;
printf("Define your Limit: ");
scanf("%d",&l);
while (n<l)
{
if (n%a!=0 || n==a)
{
if (n%3!=0 && n%5!=0 && n%7!=0|| n==3 ||n==5 ||n==7)
{
printf("%d is Prime no.\n",n);
}
else
printf("%d is Composite no.\n",n);
}
else
printf("%d is Composite no.\n",n);
n++;
}
}

No comments:

Post a Comment