Tuesday, 20 March 2018

Armstrong Numbers in C++

//Generate Series of Armstrong Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int r;
 long n=0,c,sum=0,temp;
 cout<<"Enter the upper limit\n";
 cin>>n;
 cout<<"Armstrong Numbers are\n";
 for(c=1;c<=n;c++)
 {
  temp=c;
  while(temp!=0)
  {
   r=temp%10;
   sum=sum+r*r*r;
   temp=temp/10;
  }
  if(c==sum)
  cout<<c<<"\t";
  sum=0;
 }
 getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.