Filled Under:

Sum of digits program in C

Sum of digits in C

Sum of digits program in C

 In this program, I have discussed about Sum of digits program in C.


#include<stdio.h>
int main()
{int sum=0,n,k;
printf("Enter the number:");
scanf("%d",&n);
while(n>0)
{k=n%10;
n=n/10;
sum=sum+k;
}
printf("\nThe sum is %d", sum);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved