Computer Science, asked by gayatrigangurde1999, 9 months ago

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

Answers

Answered by Yamini1999
3

Answer:

#include <iostream>

using namespace std;

int main()

{

int n,sum=0,temp,p;

cin>>n;

temp=n;

while(n>0)

{

p = n%10;

sum = sum + (p*p*p);

n = n/10;

}

if(temp == sum)

{

cout<<"Kindly proceed with encrypting\n";

}

else

{

cout<<"It is not an Armstrong Number\n";

}

return 0;

}

Answered by sreesaikandalam
3

Answer:

#include <iostream>  

#include <cmath>

using namespace std;  

int main() {

  int num, digitSum, temp, remainderNum, digitNum ;

 cin>>num;

  temp = num;

  digitNum = 0;

  while (temp != 0) {

     digitNum++;

     temp = temp/10;

  }

  temp = num;

  digitSum = 0;

  while (temp != 0) {

     remainderNum = temp%10;

     digitSum = digitSum + pow(remainderNum, digitNum);

     temp = temp/10;

  }

  if (num == digitSum)

     cout<<"Kindly proceed with encrypting";

  else

     cout<<"It is not an Armstrong number";

  return 0;

}

Similar questions