C # calculate the number of daffodils !,

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.