Write a program in C++ to generate and show the first 15 Narcissistic decimal numbers
- برمجة سي بلس بلس
- برمجة
- 2021-05-13
- MarwaMohammed
الأجوبة
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "\n\n Find the first 15 Narcissistic decimal numbers: \n";
cout << " -----------------------------------------------------\n";
cout << " The first 15 Narcissistic decimal numbers are: \n";
int i,ctr,j,orn,n,m,sum;
orn=1;
for (i=1;i<=15;)
{
ctr=0;
sum=0;
n=orn;
while(n>0)
{
n=n/10;
ctr++;
}
n=orn;
while(n>0)
{
m=n % 10;
sum=sum+pow(m,ctr);
n=n/10;
}
if(sum==orn)
{
cout<<orn<<" ";
i++;
}
orn++;
}
cout<<endl;
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
