Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Functii recursive.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- int max(int, int);
- int min(int, int);
- int cmmdc(int, int);
- int cmmdc2(int, int);
- int sumaCifrelor(int);
- int compNumar(int);
- int invers(int, int);
- int isPrime(int, int);
- void divizori(int, int);
- void factor(int, int, int);
- int main()
- {
- factor(18, 2, 0);
- _getch();
- return 0;
- }
- int max(int a, int b) {
- if (a > b) return a;
- else
- return max(b, a);
- }
- int min(int a, int b) {
- if (a < b) return a;
- else
- return min(b, a);
- }
- int cmmdc(int a, int b) {
- if (a == b || a == 0)
- return b;
- else
- if (b == 0)
- return a;
- else
- if (a > b)
- return cmmdc(a - b, b);
- else
- return cmmdc(a, b - a);
- }
- int cmmdc2(int a, int b) {
- if (a == 0)
- return b;
- if (b == 0)
- return a;
- else
- return cmmdc(b, a%b);
- }
- int sumaCifrelor(int n){
- if (n == 0)
- return 0;
- else
- return n % 10 + sumaCifrelor(n / 10);
- }
- int compNumar(int nr) {
- int cif;
- cin >> cif;
- if (cif<0 || cif>9) return nr;
- else
- return compNumar(nr * 10 + cif);
- }
- int invers(int n, int p) {
- if (n < 10) return n+p;
- else
- return invers(n / 10, 10 * (p + n % 10));
- }
- int isPrime(int nr, int i) {
- if (i == 1) return 1;
- else
- return (nr%i != 0) && (isPrime(nr, i - 1));
- }
- void divizori(int n, int d) {
- if (d <= n / 2) {
- if (n%d == 0) cout << d << " ";
- divizori(n, d + 1);
- }
- }
- void factor(int n, int f, int p) {
- if (n > 1)
- if (n%f == 0) factor(n / f, f, p + 1);
- else{
- if (p!=0)
- cout << f << " la puterea " << p << endl;
- factor(n, f + 1, 0);
- }
- else if (p!=0) cout << f << " la puterea " << p << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement