Introduction

The main purpose of this blog is to share our experience with the world and get experience from the world. This will be a new venture for us and we are sure, we shall learn a lot with it. we will try to Explore our mind which will be very helpful for all us. As from its name, its a blog covering all the topics. we will try to post all the interesting topics and give our opinion. Do give your point of view in comments.


"NAVIGATE VIA BLOG ARCHIVE ON RIGHT TO GET WHAT YOU ARE LOOKING FOR"


Thursday, January 27, 2011

C CODE 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