Find Sum of Digits of the Number using Recursive Function in C Programming

July 29, 2024 No Comments » Hits : 805





#include<stdio.h>int rem,sum;int calsum(int n){if(n!=0){ rem=n%10; sum=sum+rem; calsum(n/10);}
  return sum;}//------------------------------------------------intmain(){int num,val; clrscr();printf("\nEnter a number: ");scanf("%d",&num); val=calsum(num);printf("\nSum of the digits of %d is: %d",num,x);return0;}

Output :

Enter a number: 123
Sum of the digits of 123 is : 6

Incoming search terms: