C language implements output of all narcissus numbers

王林
Release: 2020-05-13 11:31:10
Original
19217 people have browsed it

C language implements output of all narcissus numbers

What is the Narcissus Number?

The "daffodil number" refers to a 3-digit number in which the sum of the cubes of the digits is equal to the number itself.

Implementation code:

#include<stdio.h>
int main()
{
	int a,b,c;
	for(int i=100;i<=999;i++)
	{
		a=i/100;  //百位数 
		b=(i/10)%10;  //十位数 
		c=i%10;  //个位数 
		if(a*a*a+b*b*b+c*c*c==i) 
		printf("%d\n",i);
	}
 	return 0;
}
Copy after login

The output results are as follows:

C language implements output of all narcissus numbers

Recommended tutorial: c language tutorial

The above is the detailed content of C language implements output of all narcissus numbers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template