Advertisement
Catdisk

Pregunta 4

Sep 6th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4.  
  5. using namespace System;
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int numeroIngresado;
  11.     int primer, segundo, tercero, cuarto;
  12.     int suma;
  13.  
  14.     cout << "Ingrese un numero de 4 digitos: ";
  15.     cin >> numeroIngresado;
  16.  
  17.     primer = numeroIngresado / 1000;
  18.     segundo = (numeroIngresado % 1000) / 100;
  19.     tercero = (numeroIngresado % 100) / 10;
  20.     cuarto = numeroIngresado % 10;
  21.  
  22.     cout << primer << " " << segundo << " " << tercero << " " << cuarto << endl;
  23.  
  24.     suma =  ((primer  % 2 != 0) * primer ) +
  25.             ((segundo % 2 != 0) * segundo) +
  26.             ((tercero % 2 != 0) * tercero) +
  27.             ((cuarto  % 2 != 0) * cuarto );
  28.  
  29.     cout << "La suma de los digitos impares es: " << suma;
  30.  
  31.     _getch();
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement