Thursday, September 4, 2014

Write a function to obtain the prime factors of this number.


Problem

A positive integer is entered through the keyboard. Write a function to obtain the prime factors of this number.

Solution - Code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void pr_fact();
main()
{
 pr_fact();
 system("pause");
}
void pr_fact()
{
 int x,y,i;
 printf("Enter any integer number : ");
 scanf("%d",&x);
 printf("Prime factors of %d : \n",x);
 i = 1;
 while( i <= x )
 {
  if ( x%i==0 )
   printf("%d\n",i);
  i++;
 }
}

Sample Output


1 comment :

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact