Home › Forums › C Programming › To Find the Prime Factors of a Number
- This topic has 1 reply, 2 voices, and was last updated 12 years, 4 months ago by Anonymous.
Viewing 1 reply thread
- AuthorPosts
- July 1, 2012 at 10:23 am #2257AnonymousInactive1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950<br /><br />#include<stdio.h><br />#include<stdlib.h><br />#include<math.h><br />#include<ctype.h><br />#include<conio.h><br /><br />int main()<br />{<br />int x,div=2;<br /><br /><br />int i=0,j=0;<br />clrscr();<br />printf("Enter Number X : ");<br />scanf("%d",&x);<br />int num=x;<br />int *prime=(int *) malloc(x*sizeof(int));<br />printf("n Allocated n");<br />getch();<br />if (x==1 || x==0)<br />{ printf(" Number %d have no prime Factors",x);<br />*prime=0;<br />}<br />else<br />{ while(x>1)<br />{ if ((x%div)==0)<br />{ *(prime+i)=div;x=x/div;i++;printf("n Prime Factorn");<br /><br />}<br />else<br />{ div++; }<br /><br />}<br /><br /><br />}<br /><br />printf("n The Prime Factors for Number %d are :n",num);<br /><br />for(j=0;j<i;j++)<br /><br />{ printf (" %d ",*(prime+j)); }<br /><br />getch();<br />return(0);<br />}<br /><br />
- July 3, 2012 at 10:37 am #3662AnonymousInactive
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.
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.