C Program
#include<stdio.h> #include<conio.h> void main() {
clrscr(); int n,sum=0; printf("Enter a number"); scanf("%d",&n); while(n>0) { sum=sum+n%10; //adding last digit n=n/10; //removing last digit } printf("Sum of digits of the number = %d",sum); getch(); }
No comments:
Post a Comment