sum of digits in c++

                            SUM OF DIGITS PROGRAMME

// programme to find the sum of three digits number
//use header files syntax according to the compiler
#include<conio.h>
#include<iostream.h>
 
void main()
{
    int n,r;
    int sum=0;
    cout<<"enter a three digit number";
    cin>>n;
    for(int i=1;i<=3;i++)
     {
         r=n%10;
         sum=sum+r;
         n=n/10;
     }
    cout<<"the sum of "<<n<<"= "<<sum;
   getch();
 
example :    Input    = 468

                   Output  = 22 

 

//read: Syntax and explanation of for loop