需要帮助:如何编写将分数简化为最简单形式的Windows表单应用 [英] Need Help :How to write a windows form app that reduces fractions to simpliest form

查看:60
本文介绍了需要帮助:如何编写将分数简化为最简单形式的Windows表单应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013,我想知道如何编写一个程序以允许用户输入一个分数,然后在列表框中显示该分数,并在其旁边显示分数的简化形式.例如,如果用户 输入"2/4"列表框将输出"2/4 = 1/2".我一直在网上寻找操作方法,但似乎都没有.感谢您的帮助.

Hi I'm using Visual Studio 2013 and I was wondering how to write a program to allow the user to enter a fraction and then display that fraction in a list box with the reduced form of the fraction right next to it. An example of this would be if the user entered "2/4" the list box would output "2/4 = 1/2." I've been looking up online how to do this and none of them seem to work. I appreciate any help.

推荐答案

这是我第一条思路的非常简化的示例.

Here is a very simplified example of my first line of thought.

' Form1 with TextBox1, ListBox1 ' and Button1 ' no error checking included ' quick and dirty offering Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

       ListBox1.Items.Clear()

        ListBox1.Items.Clear()

Dim s作为字符串= TextBox1.Text Dim a()为String = Split(s,"/") 昏暗的顶部作为整数= CInt(a(0)) 昏暗的小数作为整数= CInt(a(1)) 昏暗的水准为Double =最高/最高 除数为Integer = 1填充 如果bott Mod除数= 0,则 如果top Mod divisor = 0那么 ListBox1.Items.Add((top \ divisor).ToString&"/''&(bott \ divisor).ToString) 万一 万一 下一个 结束子 结束班级

Dim s As String = TextBox1.Text Dim a() As String = Split(s, "/") Dim top As Integer = CInt(a(0)) Dim bott As Integer = CInt(a(1)) Dim res As Double = top / bott For divisor As Integer = 1 To bott If bott Mod divisor = 0 Then If top Mod divisor = 0 Then ListBox1.Items.Add((top \ divisor).ToString & "/" & (bott \ divisor).ToString) End If End If Next End Sub End Class


这篇关于需要帮助:如何编写将分数简化为最简单形式的Windows表单应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆