miércoles, 14 de septiembre de 2011

Comprobar primos VC++

Realizar una aplicación en Visual C++ que permita introducir un texto en un TextBox y muestre en una etiqueta los valores VERDADERO o FALSO según sea primo o no.







- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Código Fuente
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
{				 
	bool es_primo = true;
	int dato_teclado;

	dato_teclado = Convert::ToInt32 (this->txt_dato->Text);

	for (int i = dato_teclado-1; i>1; i--)
	{
		if ((dato_teclado % i) == 0)
		{
			es_primo = false;
		}
	}

	if (es_primo) this->et_primo->Text = "VERDADERO";
	else this->et_primo->Text = "FALSO";
}

No hay comentarios:

Publicar un comentario

Related Posts Plugin for WordPress, Blogger...