Prime number

Program:

#include<stdio.h>
int main()
{
int i,n,flag=0;
printf("Enter number: ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if (n == 1)
 {
      printf("1 is neither a prime nor a composite number.");
  }
 else
 {
      if(flag==0)
{
printf("%d is a prime number",n);
}
else
{
printf("%d is not a prime number",n);
}
}
return 0;
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...