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 FACTORS OF A NUMBER

#include<stdio.h>
int main()
{ int x,q,no,s;
  printf("Enter the Number: "); // the number to be operated
  scanf("%d",&no);
  printf("\nThe Prime Factors of %d Follow:\n" ,no);
  for ( x=2;(no/x)>=1;x++) // entry to only loop which lets only prime    factors to be printed
      { if ((no%x)==0)        // prints the factor if mod is 0
         {printf("%d  ",x);
          s=(no/x);           
          no=s;          // changes the number for entry into loop again
          x=x-1;        // it makes the x same when entered again in the loop
         }
      }// loop end 
  printf("\n");
  return 0;
}

No comments:

Post a Comment

Related Posts with Thumbnails