Computer Science, asked by bharathde9, 1 year ago

Write a function in C++ to calculate the sum of digits of an integral number

Answers

Answered by josimagic
2

#include <iostream.h>

using namespace std;

// function declaration

int sumcalc(int num);

cout << "Enter a number : ";

cin >> num;

     sum = sumcalc(num);

    cout << “ sum of digits is : “<< sum<<endl;

   return 0;

}                

//function to calculate sum

int max(int num) {

  int n, sum = 0;

              n= sum;

              while(n!=0){

                              sum = sum + n%10;

                              n = n/10;

               }return sum;

}

Similar questions