Matrix Foundation/*================================================================== Title: Enter a positive integer. It is decomposed into a mass-dependent type, such as: 60=2*2*3*5; if it is a prime number, the output is as follows: 307 is a prime number!==================================================================*/#include <stdio.h>void main () {int n,m,c , i,k,y[40];p rintf ("Enter a positive integer:"), scanf ("%d", &n), while (n>0) {m=n;c=0;k=m/2;for (i=2;i<=k;i++) {while (m%i==0 ) {y[c++]=i;m/=i;}} if (m>1) y[c++]=m;if (c==1) printf ("%d is a prime number \ nthe", N), else{printf ("%d=%d", N,y[0]), for (i=1;i<c;i++) printf ("*%d", y [i]); printf (".");} printf ("\ n \ nyou continue to enter a positive integer:"); scanf ("%d", &n);}} /*====================================================================: This compilation method may be more abstract! More difficult to understand is m>1,c==1,m%i==0;m>1, then m at least 2, indicating that there is at least one qualitative factor (because 2,3, are prime), so the storage factor of the array y[] at least one element. That is, if c>=1; c==1, then y[] happens to have an element, it must be this number itself!
So this number is prime! M%i==0, which shows that M can be divisible by I, i.e. I is the factor of M, since it starts from 2. So it must be a prime number (if the reader is not clear, you can review the nature of prime numbers.) M/i, is to decompose m into a number Shu multiplied by a mass factor, and then continue to look for the Shu factor through the for and while loops!
Until it is not found, the loop ends and the output is formatted as well! =====================================================================*/
Basic algorithm of C language 34-decomposition factorization (method one)