Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Bautista Casals
Labo-Algo1
Commits
4df49a34
Commit
4df49a34
authored
2 years ago
by
Bautista Casals
Browse files
Options
Download
Email Patches
Plain Diff
Add new file
parent
5ed683ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
numeroCombinatorio.cpp
numeroCombinatorio.cpp
+40
-0
No files found.
numeroCombinatorio.cpp
0 → 100644
View file @
4df49a34
#include <iostream>
int
factorial
(
int
n
)
{
int
i
=
1
;
int
prod
=
1
;
while
(
i
<=
n
)
{
prod
=
prod
*
i
;
i
=
i
+
1
;
}
return
prod
;
}
int
numeroCombinatorio
(
int
n
,
int
k
)
{
//Calculo el numero combinatorio usando
//los factoriales
return
(
factorial
(
n
))
/
((
factorial
(
n
-
k
))
*
(
factorial
(
k
)));
}
int
main
()
{
//Ingreso de datos
std
::
cout
<<
"Ingrese un numero para n: "
<<
std
::
endl
;
int
n
=
0
;
std
::
cin
>>
n
;
std
::
cout
<<
"Ingrese un numero para k: "
<<
std
::
endl
;
int
k
=
0
;
std
::
cin
>>
k
;
//salida de resultados
std
::
cout
<<
"El numero combinatorio entre los valores ingresados es: "
<<
std
::
endl
;
;
if
(
n
==
k
or
k
==
0
)
{
std
::
cout
<<
"es 1"
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"es "
<<
numeroCombinatorio
(
n
,
k
)
<<
std
::
endl
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment