Skip to main content

Program to check weather a number is amstrong or not.

Hi guys,

This is a simple cpp program to check weather a number is amstrong or not.

A number is amstrong if the sum of the cubes of the digits of the number is the same number. Thus as a common example we use the number 153.

Then,
1^3=1
5^3=125
3^3=27
the total will be 1+125+27=153 ,the same number.

In the program, we:

  • input the number to be checked.
  • extract each digits from the number.
  • take cubes.
  • add up.
  • check the result with the given number.
  • display the result.

Now try the program given below:



//amstrong
#include<conio.h>
#include<iostream.h>

class dom
{
int dgt,dum,flag;
public:
void get()
{
cout<<"Enter the digit:";
cin>>dgt;
cout<<"done!";
dum=dgt;
}
void check();
void disp()
{
if(flag==1) cout<<"\n Awesome! Amstrong";
else cout<<"\noops! not *_* TRY AGAIN";
}

};
void dom::check()
{
int q,sum=0;
while (dum!=0)
{
q=dum%10;
sum=sum+q*q*q;
dum=dum/10;
}
cout<<"\n\ncubed:"<<sum;
if (sum==dgt) flag=1;
else flag=0;
};

void main()
{
clrscr();
dom obj;
obj.get();
obj.check();
obj.disp();
getch();
}

Good luck.

Comments

Popular posts from this blog

Talky Messenger Documentation & Setup

( Github ) Just created a chat app that runs in Node and Socket. the attempt was worthy. Talky is a messenger app built with Node, Express, Socket, Angular & Bootstrap. It's like a server-client structure. (But obviously not like the one we done at OS lab using shared memory). It has a broadcasting structure. Talky does not keep a log on chat. i.e., It doesn't have a memory or database. When we close the browser window, chat history is lost. There I also added a basic console, protected by a password, to send real-time notifications to active clients. The name 'Talky' was suggested by a friend of mine. (hey, thank you for that. The fact is that I am not really good at naming...😝) What if sometimes your college blocks WhatsApp? Try Talky. ( There is also a website on internet in the name of 'Talky' which has no connection with this one. ) Download Talky Messenger To use Talky, all you need is 3 things: Node server Source code...

4 tiny questions you fail easily.

Below are four (4) questions and a bonus question. You have to answer them instantly. You can't take your time, answer all of them immediately. OK?        Let's find out just how clever you really are .     Ready?  GO!!! (Scroll down)  Question 1 : You are participating in a race. You overtook the second person. What position are you in?  ......  ......  ......  ......  ......  ......  ......  ......  ......  ......   ......   ......   ......   ......   ......   ......   ......  ......  ......  ......  -first?, lol absolutely wrong! -If you overtake the second person and you take his place, you are second!  Try not to screw up in the next question.  ...

Formia - A Simulation of Google Forms. Part 1 - My Experience

This time I would like to share one of the exciting moments in my life, in which I understood what the Client - Server Concept means and by the Grace of God , simulated one of the Internet Giant's product, Google Forms from scratch. I finished the project a couple of months ago. Here is the story. (and the project ). Analysis page, See more screenshots Screenshots Install Formia. What it is? Formia is an incredible web application for Massive Feedback Analysis. Developed on May 2015. More than  4000 lines of codes. Flexible. Well structured. This can be viewed as a simulation of  Google Forms , a product hosted by the  Internet Giant, Google. Service available in  mobile, laptop, tabs . Languages Formia is constructed on  7 languages , including PHP, AJAX, JS, SQL etc. The Analysis part utilizes  Google APIs  which is one of the coolest (and  hottest ) feature. Usability Formia is optimized for easine...