将数字的8位数字各自乘以其相应的加权系数. [英] Multiply each of the 8 digits of the number by its corresponding weighting factor.

查看:78
本文介绍了将数字的8位数字各自乘以其相应的加权系数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个用于税收的文本框,该文本框应仅输入8位数字和
每个数字都乘以权重系数,这8个乘积结果的总和应除以11,如果余数为零,则应显示税号有效,否则应显示消息无效税号...

例如,我在文本框中输入以下数字
81854402:

1.(8x10)+(1x7)+(8x8)+(5x4)+(4x6)+(4x3)+(0x5)+(2x1)
2. 80 + 7 + 64 + 20 + 24 + 12 + 0 + 2 = 209
3. 209/11 = 19,余数为零
4.余数为零,因此该数字有效.


我可以知道如何在C#应用程序中实现此逻辑吗?..


等待您的最早答复...

问候,
karthika

解决方案

  string  txtnumber = txtNumber.Text.Replace(" " );
字符串 [] nums = txtnumber.ToCharArray();
 int  val =  0 ;
 for ( int  i =  0 ; i< ; nums.Length; i ++)
{
  val + =((( int )(nums [i]-'   int  sum =  0 ;
sum = sum + Convert.ToInt32(textbox.text.Substring( 0  1 ))* 10;

// 继续输入其他数字,注意空格

 int 剩余数=总% 11 ; // 模运算符在C#中为% 


hi

i have a text box for the tax that text box should enter only 8 digit numbers and
each digit is multiplied with there weight factor and sum of those 8 product result should divide by 11 and if the remainder is zero it should show that the tax number is valid otherwise it should show the message invalid tax number...

for example i''m entering the below number in textbox
81 854 402:

1. (8x10) + (1x7) + (8x8) + (5x4) + (4x6) + (4x3) + (0x5) + (2x1)
2. 80 + 7 + 64 + 20 + 24 + 12 + 0 + 2 = 209
3. 209/11 = 19, remainder zero
4. The remainder is zero, so the number is valid.


may i know how to implement this logic in the c# application .....


Awaiting for your Earliest Reply...

with regards,
karthika

解决方案

string txtnumber = txtNumber.Text.Replace(" ","");
string[] nums = txtnumber.ToCharArray();
int val=0;
for(int i=0; i< nums.Length; i++)
{
  val += ((int)(nums[i]-'0'))*WEIGHT[i];
}


Since it''s a textbox you have the text property (a string). This should get you started (note: code not tested, but it should give you the idea):

int sum = 0;
sum = sum + Convert.ToInt32(textbox.text.Substring(0,1))*10;

// continue with other digits, watching out for the spaces

int remainder = sum % 11; // modulo operator is % in C#


这篇关于将数字的8位数字各自乘以其相应的加权系数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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