google search

Popular Posts


Welcome to BCA Notes

>>>>>>>>>>>>>>>>

Visitors

Search This Blog

Blogger templates

Visitor Map


Monday, 7 July 2014

Write a c program to find out sum of digit of given number

//Write a c program to find out sum of digit of given 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;
}

Sample output:
Enter a number: 123
Sum of digits of number:  6

0 comments:

Post a Comment