C and C++ Programming Resources

To Find the Prime Factors of a Number

Complete discussion on C/C++ and Object Oriented Behavior of C++.

To Find the Prime Factors of a Number

Code: Select all
` #include<stdio.h>#include<stdlib.h>#include<math.h>#include<ctype.h>#include<conio.h>int main(){int x,div=2;int i=0,j=0;clrscr();printf("Enter Number X : ");scanf("%d",&x);int num=x;int *prime=(int *) malloc(x*sizeof(int));printf("\n Allocated \n");getch();if (x==1 || x==0) { printf(" Number %d have no prime Factors",x);    *prime=0; } else     { while(x>1)   {  if ((x%div)==0)      { *(prime+i)=div;x=x/div;i++;printf("\n Prime Factor\n");      }      else          { div++; }    }       }    printf("\n The Prime Factors for Number %d are  :\n",num);   for(j=0;j<i;j++)     { printf (" %d ",*(prime+j));   }     getch();     return(0);}`
ashine1980

Posts: 3
Joined: Sun Jul 01, 2012 10:55 am

Re: To Find the Prime Factors of a Number

Please visit the Site http://contest.collectiva.in/Contest/ContestTraining.aspx To learn Fundamentals of C Programming in Tamil. It is very useful for the Beginners.
collectiva

Posts: 3
Joined: Tue Jul 03, 2012 11:26 am