Share Info With Your Friends

       
   

C program for prime number or not

#include<stdio.h>

main()
{
   int n, c = 2;

   printf("Enter a number to check if it is prime\n");
   scanf("%d",&n);

   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%== 0 )
      {
         printf("%d is not prime.\n", n);
 break;
      }
   }
   if ( c == n )
      printf("%d is prime.\n", n);

   return 0;
}

C program for prime number using function

#include<stdio.h>

int check_prime(int);

main()
{
   int n, result;

   printf("Enter an integer to check whether it is prime or not.\n");
   scanf("%d",&n);

   result = check_prime(n);

   if ( result == 1 )
      printf("%d is prime.\n", n);
   else
      printf("%d is not prime.\n", n);

   return 0;
}

int check_prime(int a)
{
   int c;

   for ( c = 2 ; c <= a - 1 ; c++ )
   { 
      if ( a%== 0 )
 return 0;
   }
   if ( c == a )
      return 1;
}
Previous
Next Post »

Thanks for your feed back we will soon reply you EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng