Thursday, 5 January 2012

C++ Program to print prime factorization



C++ Program to print prime factorization
 #include<conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
main()
    {
    clrscr();
    char line[512]; /* input string */
    short ii;   /* number to be factored */
    short j;   /* divisors */
    short p;   /* powers of j in ii */
    cout<<"Please enter the number to be factored: ";
    cin.getline(line, 512);
    ii = atoi(line);
    cout<<"The prime divisors of "<< ii<< " are/ is ";
    for (j = 2; ii != 1; j = j + 1)
    {
    if (ii % j == 0)
        {
        for (p = 0; ii % j == 0; p = p + 1)
        ii = ii / j;
        cout<< j<<" ";
        }
    }
    cout<<endl;
    getch();
    }

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More