Use the stack to break down a form of a numerous factor product.

xiaoxiao2021-03-05  32

STACK.H Download Source File:

#include

#include

const int maxentry = 20; enum error_code {fail, success, overflow, underflow}; template class stack {private: int count; type entry [maxentry]; public: stack () {count = 0;} error_code push (const type & a); error_code pop (); BOOL EMPTY () const; error_code top (type & a) const; int numBers (); → Template error_code stack :: push (const type & a) {error_code outcome = success; if (count error_code stack :: pop () {error_code outcome = success ; If (count> 0) {count -;} else outcome = fail; return outcome;} template Bool stack :: Empty () const {return count == 0;} template Error_code stack :: TOP (Type & a) const {error_code outcome = success; if (count> 0) {a = entry [count-1];} else outcome = fail; return outcome;} Template int stack :: numbers () {return count;}

Bool isprime (int N) {if (n == 1) Return False; INT K; K = SQRT (N); for (int i = 2; i <= k; i ) {= 0 ) {RETURN FALSE;} IF (i> = k 1) {return true;} else {return false;}}}

Void Prime (stack Num) {INT M = 2; // int A [255] = {0,}; // int I; int N; num.top (n); //num.pop () ; // cout << n << Endl; if (n == 1 || n == 0 || n <0) {cout << "The number you entered does not have a presence." << endl; return; }

While (n> 1) {loop1: {if (isprime (n)) {goto loop2;} else if (n% m == 0) {//cout<

}

} / * If (Num.top (i) == 1) Num.pop (); * /

LOOP2: {INT x = Num.NumBers (); for (int J = 0; j <= x-1; j ) {INT M; Num.top (m); cout << m << ""; Num. POP ();} cout << endl;

}

Prime.cpp:

#include using namespace std; #include "stack.h"

#include

Void Prime (stack ); BOOL ISPRIME (Int);

Void main () {stacked Num; int N; char s; loop1: {cout << "INPUT A Number: << Endl; cin >> N; cout <<" The prime of the number is: " << Endl; // cout << isprime (n) << endl;

Num.push (n); prime (NUM);} Cout << "Continue?" << Endl; cin >> s; if (s == 'y') {Num.Pop (); goto loop1;} Else Return;

}

转载请注明原文地址:https://www.9cbs.com/read-35064.html

New Post(0)