Saturday, 28 April 2012

Program that finds out the Prime Factors of a given number in C


#include<stdio.h>
#include<conio.h>
int main()
{
  int x,i=1,j,k;
  printf("\nEnter a number:");
  scanf("%d",&x);
  while(i<=x)
  {
     k=0;
     if(x%i==0)
     {
 j=1;
 while(j<=i)
  {
     if(i%j==0)
     {
    k++;
   }
   j++;
  }
  if(k==2)
  {
   printf("\n%d is a Prime Factor",i);
  }
   }
      i++;
   }
   getch();
   return 0;
}

No comments:

Post a Comment