step 1: Syntax While Loop
- While (condition)
- {
- //Execute Statament
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- int intNo = Convert.ToInt32(txtNo.Text.Trim());
- int intBinary;
- string strBinary = "";
- while (intNo != 0)
- {
- intBinary = intNo % 2;
- intNo = intNo / 2;
- strBinary = intBinary + strBinary;
- }
- //strBinary.Reverse();
- lblBinaryNo.Text = strBinary;
- }
You can implement while loop concept and modulo and division operation easily.
Join the conversation! Your thoughts help the community grow.