Computer Science, asked by SatyaSumanth6299, 8 hours ago

Write a function in 'c' to calculate sum of digits of an integer.use this function in main

Answers

Answered by ashwinikamath2001
0

Answer:

#include <stdio.h>

void sum(int)

int main()

{

   int n, t, sum = 0, remainder;

   printf("Enter an integer\n");

   scanf("%d", &n);

sum(n);

 }

void sum(int n)

{

 t = n;

   while (t != 0)

   {

      remainder = t % 10;

      sum  = sum + remainder;

      t  = t / 10;

   }

   printf("Sum of digits of %d = %d\n", n, sum);

   return ;

}

Similar questions