sum of digits

Sum Of Digits In C

Q. How to make program of Sum Of digit (input-> 1,2,3 output->1+2+3=6) In C #include<stdio.h> #include<conio.h> #include<math.h> void main() { long num; int r,ans=0; clrscr(); printf(“Enter 5 digit Number:->>”); scanf(“%ld”,&num); while(num>0) { r=num%10; num=num/10; ans+=r; } printf(“\nAns=%d”,ans); getch(); } After Running Program 🙂