Interview Questions   Tutorials   Discussions   Programs   

C - Write a program to generate prime factors of a given integer?




335
views
asked marvit August 18, 2014 09:34 AM  

Write a program to generate prime factors of a given integer?


           

1 Answers



 
answered By bhjahnavi   0  
/*program to find prime factors of a given number*/
#include<stdio.h>
void main()
{
 int num,i=1,j,k;
 printf("\nEnter a number:");
 scanf("%d",&num);
 while(i<=num)
 {
   k=0;
   if(num%i==0)
   {
     j=1;
     while(j<=i)
     {
      if(i%j==0)
         k++;
       j++;
     }
     if(k==2)
       printf("\n%d are prime factor",i);
   }
   i++;
  }
 }
output:
enter a number:
60
2 3 5 are prime factors
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert