Write A Program For Armstrong Number In C# .net Window Application?

1

1 Answers

Anonymous Profile
Anonymous answered
Private void btnKiemTra_Click(object sender, EventArgs e)
  {
  int k = int.Parse(txtN.Text);
  int Luuk = k;
  double LgthOfNum = txtN.ToString().Length;
  double num = 0;
  double sum = 0;
  while (k > 0)
  {
  num = k % 10;
  sum = sum + Math.Pow(num, LgthOfNum);
  k /= 10;
  }
  if (sum == Luuk)
  {
  MessageBox.Show("It is an armstrong num.");
  }
  else
  {
  MessageBox.Show("It is not an armstrong num.");
  }

  }

Answer Question

Anonymous