C # calculate the number of daffodils !,
Recently I am getting started. NET programming, slowly learned some of the portal, but also need to record the learning bit by bit, today I think, write out the daffodils code, once it passes the operation, I will post it here, share it with you, and make a record for myself.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Namespace ConsoleApplication10
{
Class Program
{
Static void Main (string [] args)
{
For (int I = 100; I <1000; I ++) // cycles.
{
Int hundred = I/100; // obtain the number of digits.
Int ten = (I-hundred * 100)/10; // obtain the 10-digit number.
Int gewei = I-hundred * 100-ten * 10; // obtain the single digit
Int shuixianhua = hundred * hundred + ten * ten + gewei * gewei; // defines the addition of each single digit.
If (shuixianhua = I) // if the number of daffodils is the same as the number of our cycles
{
Console. WriteLine ("daffodils {0}", I); // The number is the number of daffodils. print the number of daffodils.
}
}
Console. ReadKey (); // wait for any character to be entered
}
}
We run the result: