How do I add the 2 digits of a number?

Hi, how do I add the 2 diggits of a number? For example:
1
2
3
4
5
int num = 15;

sscanf(num, "%1d%1d", &n1, &n2); // do i have to convert this num to a char?

cout << "N1 + N2 = " << n1 + n2; // 6  ??? 


Any assistance will be appreciated. Thanks.
Try this:
1
2
3
4
int num=15;
n1=num/10; // Get 10s digit
n2=num%10; // Get 1s digit
cout << n1+n2;
Thank you very much demosthenes2k8. It worked.
Topic archived. No new replies allowed.