private void button1_Click(object sender, EventArgs e) { string temp = textBox1.Text; int Bound = (int)Math.Pow(2, 15); string[] temp2 = temp.Split('.'); if (long.Parse(temp2[0]) > Bound) { textBox2.Text = "overflow"; return; } string Ans1; if (temp2[0][0] == '-') { Ans1 = Convert.ToString(int.Parse(temp2[0].Substring(1, temp2[0].Length - 1)), 2); } else { Ans1 = Convert.ToString(int.Parse(temp2[0]), 2); } if (Ans1.Length > 15) { textBox2.Text = "overflow"; return; } Ans1 = Ans1.PadLeft(15, '0'); if (temp2[0][0] == '-') { Ans1 = "1" + Ans1; } else { Ans1 = "0" + Ans1; } if (temp2.Count() > 1) { double p = 0; string Ans2 = ""; double tempdouble = double.Parse(temp2[1]); p = Math.Pow(10, temp2[1].Length); for (int i = 0; i < 8; i++) { tempdouble *= 2; Ans2 += (int)(tempdouble / p); tempdouble %= p; } textBox2.Text = Ans1 + "." + Ans2; } else { textBox2.Text = Ans1; } }
}//private void AdjustDataGridViewSizing() private void button5_Click(object sender, EventArgs e)// [Truth table] { // Create an unbound DataGridView by declaring a column count. dataGridView1.ColumnCount = 5; dataGridView1.ColumnHeadersVisible = true; AdjustDataGridViewSizing(); // Set the column header style. DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColor = Color.Aqua; columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold); dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle; // Set the column header names. dataGridView1.Columns[0].Name = "A"; dataGridView1.Columns[1].Name = "B"; dataGridView1.Columns[2].Name = "A && B"; dataGridView1.Columns[3].Name = "A || B"; dataGridView1.Columns[4].Name = "!A"; // Populate the rows. bool A, B, Ans1, Ans2, Ans3; // A = true; B = true; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row1 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = true; B = false; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row2 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = false; B = true; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row3 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = false; B = false; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row4 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; // object[] rows = new object[] { row1, row2, row3, row4 }; foreach (string[] rowArray in rows) { dataGridView1.Rows.Add(rowArray); } // // Set the row header style. DataGridViewCellStyle rowHeaderStyle = new DataGridViewCellStyle(); rowHeaderStyle.BackColor = Color.Lime; rowHeaderStyle.Font = new Font("Verdana", 7, FontStyle.Italic); dataGridView1.RowHeadersDefaultCellStyle = rowHeaderStyle; // dataGridView1.Rows[0].HeaderCell.Value = "a"; dataGridView1.Rows[1].HeaderCell.Value = "b"; dataGridView1.Rows[2].HeaderCell.Value = "c"; dataGridView1.Rows[3].HeaderCell.Value = "d"; // dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 7); }//private void button5_Click(object sender, EventArgs e)
private void btn_click(object sender, EventArgs e) { double A, B, C; A = Convert.ToDouble(a.Text); B = Convert.ToDouble(b.Text); C = Convert.ToDouble(c.Text); double Ans1, Ans2, va; va = Math.Sqrt(B * B - 4 * A * C); Ans1 = (-B + va) / (2 * A); Ans2 = (-B - va) / (2 * A); Ans.Text = " Ans1=" + Ans1.ToString("0.0#") + " Ans2=" + Ans2.ToString("0.0#"); }