Grupo
Control de Flujo en C++
Ojetivo
1. Pida al usuario que introduzca un número.
2. Utilice el operador módulo para comprobar si el número es divisible entre 5 y 3.
3. Muestre un mensaje indicando si el número es divisible entre 5 y 3.
4. Maneje entradas tanto positivas como negativas.
Escriba un programa que compruebe si un número es divisible entre 5 y 3 simultáneamente.
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the iostream library for input and output
using namespace std; // Use the standard namespace
// Main function - the entry point of the program
int main() {
int number; // Variable to store the user's input
// Ask the user for input
cout << "Enter a number: ";
cin >> number; // Read the input number
// Check if the number is divisible by both 5 and 3
if (number % 5 == 0 && number % 3 == 0) { // If the number is divisible by both
cout << "The number is divisible by both 5 and 3." << endl;
}
else { // If the number is not divisible by both
cout << "The number is NOT divisible by both 5 and 3." << endl;
}
return 0; // Return 0 to indicate that the program executed successfully
}
Salida
Enter a number: 15
The number is divisible by both 5 and 3.
//Or for a number that is not divisible by both:
Enter a number: 7
The number is NOT divisible by both 5 and 3.
Comparte este ejercicio C++