Encrypt using Armstrong number
Nowadays, we use social media a lot. We usually send messages, pictures, etc to each other. So, encrypting and decrypting should be done properly to avoid hacking. Irin is developing a program for the same where color encrypting is done with the help of Armstrong numbers. Can you help Irin to write program to check whether a number is an Armstrong number or not.
#include
int power(int m,int n)
{
int j,i;
for(i=1,j=1;i<=n;i++)
j=j*m;
return j;
}
int arm(int n)
{
//Your code goes here
}
int main()
{
int n;
std::cin>>n;
if(arm(n)==1)
std::cout<<"Kindly proceed with encrypting";
else
std::cout<<"It is not an Armstrong number";
}
complete the code in cpp programing---//Your code goes here up in the code
Answers
Answered by
3
I don't know the answer
Answered by
5
Answer:
#include<iostream>
using namespace std;
int power(int m,int n)
{
int j,i;
for(i=1,j=1;i<=n;i++)
j=j*m;
return j;
}
int arm(int n)
{ int r,v,z=0;
if(n/1000==0)
v=3;
else v=4;
for(int i=n;i>0;i/=10)
{ r=i%10;
z=z+power(r,v);
}
if(z==n)
return 1;
}
int main()
{
int n;
std::cin>>n;
if(arm(n)==1)
std::cout<<"Kindly proceed with encrypting";
else
std::cout<<"It is not an Armstrong number";
}
Explanation:
as we know we need to take sum of cube of digits in armstrong number
but for 4 digits we have to replace cube to 4
e.g-
1634
1^4+6^4+3^4+4^4=1634
Similar questions