"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Monday, April 26, 2010

WAP to input a 3 digit number. Print the digits of unit place, tenths place and hundredths place

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

#include<process.h>


void main()
{
int n, u, t, h, r;


cout<<" Enter a number (with 3 digits) ";
cin>> n;


if( n < 100 || n > 999)
{
cout<< "\n It is not a 3 digit no. ! Abort  ";
getch();
exit(1);
}


u = n % 10; // digit of unit place 
r = n / 10; // remaining two digits
t = r % 10; // digit of tenths place
h = r / 10; // digit of hundredths place


cout<< "\n unit place Digit = " << u;
cout<< "\n ten's place Digit = " << t;
cout << "\n Hundredths place Digit = " << h;


getch();
}

1 comment:

  1. A good beginner program. Another program demonstrates how to convert a 3 digit number to words - http://mbtechno.blogspot.in/2012/04/c-program-number-in-words.html

    ReplyDelete

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.