Un entero dentro de otro

/* ======================================================================// EJ.N/A: Dados dos enteros (N y M), determinar si N ϵ M == true // ======================================================================// @Author=CarlosDAlvarez // @Date=251115 // @Lang=C++ // @MajorLnkVer=VC++2012(11) // ======================================================================// */ #include <stdio.h> #include <stdlib.h> bool NumEnNum(int,int); int main() { bool Coincide = false; int N, M, partida, N2,M2; printf("Ingrese N: "); scanf("%d", &N); printf("\nIngrese M: "); scanf("%d", &M); M2 = M; N2 = N; partida = N % 10; while(N != 0) { if (M%10 == partida) { if (NumEnNum(N, M)) { Coincide = true; N = 0; } } M = M / 10; } if (Coincide) printf("%d se encuentra en %d.\n\n\n", N2, M2); else printf("%d no se encuentra en %d.\n\n\n", N2, M2); system("pause"); } bool NumEnNum(int N, int M) { while ( (M!= 0) && (N!=0) ) { if (M%10 != N%10) { return false; } else { M = M / 10; N = N / 10; } } return true; }
Determinar si un entero N, se encuentra dentro de otro M.

No se usa manipulación de caracteres.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.