Have a Read!

Hi Everyone.
The idea for this page is to provide new c users simple c tutorials to learn how to develop the logic and more importantly correct way to write syntax.
ENJOY !!!

Thursday, January 27, 2011

C PROGRAM FOR PRIME NUMBER way2

//This one is a little complicated
#include<stdio.h>
int main()
{ int x,q,no,s,originalno;
  printf("Enter the Number: ");
  scanf("%d",&no);
  originalno=no;
  for ( x=2;(no/x)>=1;x++)
      { if ((no%x)==0)      
         {
      if (x==originalno)
          {printf("%d is a PRIME number\n",originalno);}
      s=(no/x);           
          no=s;         
          x=x-1;       
         }
      }
if(x!=originalno)
  {printf("%d is not a prime number\n",originalno);}
  return 0;
}

No comments:

Post a Comment

Related Posts with Thumbnails