Write a program in C++ to find Narcissistic decimal numbers within a specific range

  • برمجة سي بلس بلس
  • برمجة

Write a program in C++ to find Narcissistic decimal numbers within a specific range

Sample Output:

Find the Narcissistic decimal numbers between a specific range:       
 --------------------------------------------------------------------  
 Input the lower limit: 25                                             
 Input a upper limit: 200                                              
 The Narcissistic decimal numbers between 25 and 200 are:              
 153

الأجوبة

#include <iostream>
#include <cmath>
using namespace std;
int main() 
{
    int nl,nu;
 cout << "\n\n Find the Narcissistic decimal numbers between a specific range: \n";
 cout << " --------------------------------------------------------------------\n";
 	cout << " Input the lower limit: ";
    cin>>nl;	
	cout << " Input a upper limit: ";
    cin>>nu;		
  cout << " The Narcissistic decimal numbers between "<<nl<<" and "<<nu<<" are: \n";
    int i,ctr,j,orn,n,m,sum;
    for(orn=nl;orn<=nu;orn++)
    {
    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<<" ";
    }
}
	cout<<endl;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...