//sum of the digits#include<stdio.h>int main(){int num,sum,r;sum=0;printf("\n Enter the number ");scanf("%d",&num);while(num){r=num%10;sum=sum+r;num=num/10;}printf("\n The sum of the digits %d",sum);return 0;}Sample output:Enter a number: 45Sum of digits of number: 9

Advertisements

Advertisements

[…] Sum of the digits of a number […]