Program: Sum of digits of an integer


    #include <iostream.h>
    main()
    {
        int num , temp , sum = 0 ;
        cout<<"Enter an integer value :\n";
        cin>>num;
        do
        {
            temp = num % 10 ;
            sum = sum + temp ;
            num = num / 10 ;
        }
        while (num != 0) ;
        cout<<"The sum of individual digits is "<<sum;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|