In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
// creating an Armstrong function
int armstrong()
{
int a,b,c,d;
cout<<"Enter number you want to check for Armstrong number";
cin>>a;
c=0;
b=a;
while(b!=0)
{
d=b%10;
c=c+(d*d*d);
b=b/10;
}
if(a==c)
{
cout<<a<<" :The number is an Armstrong number";
}
else
{
cout<<a<<" :The number is not an Armstrong number";
}
return a;
}
void main()
{
clrscr();
armstrong();
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int armstrong()
{
int a,b,c,d;
cout<<"Enter number you want to check for Armstrong number";
cin>>a;
c=0;
b=a;
while(b!=0)
{
d=b%10;
c=c+(d*d*d);
b=b/10;
}
if(a==c)
{
cout<<a<<" :The number is an Armstrong number";
}
else
{
cout<<a<<" :The number is not an Armstrong number";
}
return a;
}
int main()
{
armstrong();
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP