Tuesday, 15 December 2015

Program to get single digit number from double

Program to find single digit number from double. 
Example: input -->    89
                output->     8 + 9 = 17
                output->     1 + 7 = 8  (single digit)

(It was given in Mid-term Exam in my First term)

#include<iostream>
#include<conio.h>
using namespace std;
int n, a, b, c, d, e;
int main()
{
cout << "Put any two digit number = ";
cin >> n;

while (n > 10){
a = n % 10;
b = n / 10;
c = a + b;
cout << b << " + " << a << " = " << c << "\n";
n = c;

}
_getch();
}

No comments:

Post a Comment