Chapter+3_Ex+3.10


 * Exercise number:3.10**


 * Description of objective:**

Write a Program that accepts a two-digit number and displays the digits each on a single line. The program output should look similar to: Enter a two-digit number: I The first digit is 2 The second. diqit is 7

Modify the program to work for a three-digit number. Modify the program to report the sum of the digits of a three-digit number:

Enter a three-digit number: 274 The first digit is 2 The second digit is j The third disit is 4 The sum of the dioits is 13


 * Code:**

code format="cpp"
 * 1) include


 * 1) include

using namespace std;

int main(int argc, char *argv[])

{

int number;

cout<<"Enter a 3-digits number: ";

cin>>number;

int first,second,third;

first = number/100;

second = (number%100)/10;

third = number%10;

cout<<endl<<"The first digit is "<<number/100;

cout<<endl<<"The second digit is "<<(number%100)/10;

cout<<endl<<"The third digit is "<<number%10;

cout<<endl<<"Total: "<<first+second+third;

cin.ignore(100,'\n');

cin.get;

system("PAUSE");

return EXIT_SUCCESS;

}

code