Home >Backend Development >C#.Net Tutorial >C language implements output of all narcissus numbers

C language implements output of all narcissus numbers

王林
王林Original
2020-05-13 11:31:1019240browse

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;
}

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!

Statement:
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