### Q4 write a window application in C# for Armstrong number.

It is said to be an Armstrong number if and only if when we find out number’s each digit mod and cube them and add then number will be same such as the original number. The form looks like as follows:

Here textbox accept number and first it will be converted into integer number and assigned to the variable n. the code is as follows:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace CArmstrong

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

int n = Convert.ToInt32(textBox1.Text);

int temp = n;

int sum = 0;

while(n > 0)

{

sum = sum + (n%10) * (n%10) * (n%10);

n/=10;

}

if(temp == sum)

{

MessageBox.Show("Number "+temp +" is armstrong");

}

else

{

MessageBox.Show("Number "+temp +" is not armstrong");

}

}

}

}

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace CArmstrong

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

int n = Convert.ToInt32(textBox1.Text);

int temp = n;

int sum = 0;

while(n > 0)

{

sum = sum + (n%10) * (n%10) * (n%10);

n/=10;

}

if(temp == sum)

{

MessageBox.Show("Number "+temp +" is armstrong");

}

else

{

MessageBox.Show("Number "+temp +" is not armstrong");

}

}

}

}

We have made a copy of original number as temp. after that we have performed the logic inside the loop and calculated sum of each digit cube of number and assign it to the sum variable. After that we have checked that if temp== sum then number is armstrong otherwise not. The output is as follows: