Number of daffodils

Source: Internet
Author: User

The number of daffodils is also called Armstrong number.

Narcissus number refers to an n-digit number (n≥3) , and the sum of the n power of the number on each bit of it is equal to its own. (Example: 1^3 + 5^3 + 3^3 = 153)

Ask if the number you entered is a daffodil number

This problem corrected me a wrong understanding, I always thought that the number of daffodils is the cubic and equal to the number of each person, because it is often asked for a three-digit number.

The full out code is as follows:

#include "oj.h"//function: Determine whether the input Nvalue is Narcissus number//input: Nvalue is a positive integer//output: no//return: If the input is Narcissus number, return 1, otherwise return 0unsigned int isdaffodilnum ( unsigned int  nvalue) {if (nvalue<100) return 0;long  n=nvalue;long  sum=0;int i;int cnt=0;int tmp=1;while (Nvalue) {nvalue/=10;cnt++;} Nvalue=n;while (nvalue) {tmp=1;i=nvalue%10;for (int j=0;j<cnt;j++) {tmp*=i;} sum+=tmp;nvalue/=10;} if (sum==n) return 1;    else    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Number of daffodils

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.