#include<stdio.h> #include<conio.h> main() { int r,n,m,sum; //clrscr(); printf("Enter a positive Integer :"); scanf("%d",&n); if(n<0) printf("The given number is not +ve Integer"); else { sum=0; m=n; while(m!=0) { r=m%10; sum+=r; m/=10; } printf("The given number =%d\n",n); printf("Sum of digits of the given number is:%d",sum); } }
You can find the flow chart for the above code here.
OUTPUT:
Enter a positive Integer :456 The given number =456 Sum of digits of the given number is:15