/ Undifined / 17 - WAP to find the sum of digits of the entered number.

17 - WAP to find the sum of digits of the entered number.

WAP to find the sum of digits of the entered number. 
#include<stdio.h>
int main(){
  int num,sum=0,r;
  printf("Enter a number: ");
  scanf("%d",&num);
  while(num){
      r=num%10;
      num=num/10;
      sum=sum+r;
  }
  printf("Sum of digits of number:  %d",sum);
  return 0;
}
Output 
Enter a number: 123
Sum of digits of number:  6

about author

Blogger Sens it website about blogger templates and blogger widgets you can find us on social media
Previous Post :Go to tne previous Post
Next Post:Go to tne Next Post

No comments:

Post a Comment