Matrix Basics
/*
==================================================================
Title: Enter a positive integer to decompose it into a mass-dependent type, such as: 60=2*2*3*5; if it is a prime number, the output
Such as: 307 is a prime number!
==================================================================
*/
#include <stdio.h>
void Main ()
{
int n,m,c,i,k,y[40];
printf ("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 \ 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);
}
}
/*
====================================================================
Evaluation:
This compilation method may be more abstract! More difficult to understand is the m>1,c==1,m%i==0;m>1, then M is at least 2, indicating
There is at least one quality factor (because 2,3, all prime numbers), so the storage Factor array y[] contains at least one element! namely c>=1;
If c==1, then y[] happens to have an element, it must be this number itself! So this number is prime! M%i==0, Description m
Can be divisible by I, that is, I is the factor m, because it is starting from 2, so must be prime (if the reader does not understand, can be in the temperature
Learn the nature of prime numbers! ), m/i, is to decompose m into a number Shu multiplied by the mass factor, and then continues through the for and while loops
Look for the quality factor of Shu! Until it is not found, the loop ends and the output is formatted as well!
=====================================================================
*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Basic algorithm of C language 34-decomposition factorization (method one)