C program to find the sum of the digits.

 

01 #include<stdio.h>
02
03 int main()
04 {
05 int n,num,x,sum=0;
06 printf("Enter a number=");
07 scanf("%d",&n);
08
09 while(n>0)
10 {
11 x=n%10;
12 sum=sum+x;
13 n=n/10;
14 }
15 printf("Sum of digits of a number=%d",sum);
16
17 return 0;
18 }
 
 
OUTPUT :

Enter a number : 123

Sum of digits of a number : 6

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.