1//program to find the sum of digits:
2
3#include<stdio.h>
4int main()
5{
6 int num,sum=0,r,temp;
7 printf("Enter the number:\n "); //taking input from the user
8 scanf("%d",&num);
9
10 temp=num; //assigning num to temporary variable
11
12 while(temp!=0)
13 {
14 r=temp%10;
15 sum=sum+r;
16 temp=temp/10;
17 }
18 printf("\nGiven number = %d",num);
19 printf("\nSum of the digits = %d",sum);
20}
21
22//code By dungriyal
1Enter the number
2300
3Given number = 300
4Sum of the digits 300 = 3
5
6
7Enter the number
816789
9Given number = 16789
10Sum of the digits 16789 = 31