#include<stdio.h> #include<conio.h> void main() { int n,sum=0,r; clrscr(); printf("enter a number:"); scanf("%d",&n); while(n!=0) { r=n%10; sum=sum+r; n=n/10; } printf("the sum of the digits of the given no. is:=%d",sum); getch(); } |
Output:-
Explanation:
enter the number:34=3 + 4 =7
enter the number:59=5 + 9=14
______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________
Post a Comment