Friday 28 September 2012

Function007

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

#include <stdio.h>
#include <conio.h>
void pf ( int );                                              /* Function prototype declaration */
void main ( )
{     
        int    no;
        clrscr ( );
                            
        printf("\n\n\n\n\t\t Enter a number...:"); scanf("%d", &no);
            
        pf ( no );                                             /* Function calling */
        getch ( );
}          
                           
void pf ( int    x )                                          /* Function Definition */
{                          
                            
        int      a = 2 ;
        printf("\n\n\n\t\t Prime Factors of %d are....:", x);
                              
        while ( x != 1 )
        {                             
                      if ( x % a == 0 )
                      {                   
                                    printf(" %d,", a );
                      }                                   
                      else                                     
                      {                                  
                                    a++;
                                    continue;
                      }
                      x = x / a;
        }
}
Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...