Pages

Subscribe:

Find Sum OF Digits : C

This program find sum of the digits entered number.The idea is slice the every digits from number and then sum of digits.


Example :


  • Assume Entered number is : 789
  • Now slice the given number : 9 , 8 ,7.
  • Sum of the digits is : 9+8+7=24.
Sum Of Digits :

Program :

#include<stdio.h>
#include<conio.h>
void main()
{

char ch;
do{
         long int n,i,s=0 ,r;
        clrscr();
        printf("\n\tEnter Number(1-999999999):");
       scanf("%ld",&n);
       if(n>=1 || n<=999999999)
      {
        while(n>=1)
        {
           r=n%10;
           s=s+r;
           n=n/10;
        }
    }
    printf("\n\t Sum of digit:<%d>",s);
    printf("\n\t Continue(y/n):");

       ch=getch();
       }while(ch=='y'||ch=='Y');
getch();
}

Output :


No Preview





If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.