#include <iostream>
#include <math.h> // for std::pow()
unsigned int get_length(unsigned int num,const unsigned int base=10)
{
unsigned int len=1;
while(num && (num/=base))
++len;
return( len );
}
bool is_armstrong(const unsigned int num,const unsigned int base=10)
{
unsigned int len=get_length(num,base);
unsigned int sum=0;
unsigned int tmp=num;
while(tmp)
{
sum+=(unsigned int)std::pow((double)(tmp%base),(double)len);
tmp/=base;
}
return(num==sum);
}
int main()
{
std::cout << "Armstrong series (base 10):";
for(unsigned int num=0; num<=0xffffffff; ++num)
if(is_armstrong(num))
std::cout << " " << num;
std::cout << std::endl;
return(0);
}
result = a * b * c;
Build it, link it, run it.
Usually, but not always. For example the following is legal in C, but illegal in C++: char new [3] = "ABC";
answer:32 programme to print factorial of a given number in c languages
abhimanyu
#include <iostream> int main() { std::cout << "a plus bi" << std::endl; return 0; }
substracion of any two number program in c
I don't use that function in C programme.
struct A {}; // base class struct B : A {} // derived class (single inheritance).
Armstrong number means 153=(1^3)+(5^3)+(3^3)
You could use an if, but the ternary operator is especially compact for this purpose: result = a > b ? a : b;
any number