Make your own free website on Tripod.com
 

C PROGRAM:

Prime Factorization

 

Home
About Us
Discussions
Quizzes
Reflections
Flowcharts
C Programs
Feedback

 

Here is a sample Turbo C program that gives the prime factorization of a number given by the user. For expert programmers, you may need to do some adjustments if you are using another language apart from C. For those who do not understand programming, just click on the link at the bottom of this page and try the finished program out for yourself.

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#define p printf
#define s scanf
int ctr,x,n,nmod;
char cont;
main()

do
{  clrscr();
   p ("Input a number: ");
   s ("%d",&n);
   x=n;
   p ("\nThe factors are: \n");
   ctr=2;
   do
   {   nmod=n%ctr;
       if (nmod==0)
       {   p ("%d ",ctr);
           n=n/ctr;
           ctr=2;
       }
       else if (nmod!=0) ctr+=1;
   }
   while (n!=1);
   p ("\n\nDo you wish to continue [Y/N]? ");
   cont=getche();
}
while (cont=='Y'||cont=='y');
}

 


CLICK TO SEE ACTUAL PROGRAM (.zip)

Home | C PROGRAM: Determining Prime Numbers | C PROGRAM: Prime Factorization | C PROGRAM: Divisors

 

Copyright 2006. All rights reserved.

No part of this site may be reproduced without the permission of the authors.