Jump to content

[C++] Algoritm descompunere numar in C++


SkiizO
 Share

Recommended Posts

Grad tutorial: incepator mediu avansat

 

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int n,v[10],i,j=0;
system("cls");
cout<<"n= "; cin>>n;

for(i=2; i<=n; i++) {
	if(n%i==0) {
		n=n/i;
		j++;
		v[j]=i;
		i--;
	}
}

for(i=1; i<=j; i++)
	cout<<v[i]<<" ";

_getch();
}

 

Tutorial creat de mine

Link to comment
Share on other sites

Matematic:

Ai numarul 18 si vrei sa-l descompui:

18 | 2

9 | 3

3 | 3

1

 

In acest caz, programul iti va afisa 2 3 3, valorile fiind memorate in acel vector.

Sper ca ai inteles!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.