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.

Popular posts from this blog

How to pass variables to res.render() in Node.js

I was trying to figure out how to render a view inside a view, as I was stuck with this issue.

Horrible Effects of Misplaced Extensions ;)
I was using Node.js platform with ejs template engine.

My index.ejs file has an included header.ejs file.
Everything works well except that I can't pass values to the variable status in header.ejs.

Here is my abstract code...

index.ejs

header.ejs

app.js

The most funniest solution ever!
The solution is as easy as this.
Just remove .ejs extension from the include command.
I spent at least an entire night to figure it out.

Talky Messenger Documentation & Setup

(Github)
Just created a chat app that runs in Node and Socket. By the Grace of God, this 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 serverSource code.Three commands.