program to sum of digits of a number in c



Program to sum of digits of a number in cc program to sum the digit of number program first find the digit of number from the reverse order and then sum up this constant into a variable. Let us see how the sum of digit of number is found:

248 = 2 + 4 + 8 = 14

program to sum of digits of a number in c

#include <stdio.h>
#include <conio.h>

int main()
{
    int number ,a , b=0;
    printf("enter the number to number up the digits\n");
    scanf( "%d", &number );

    while(number > 0 )
    { 
         a = number % 10;
         b = b + a ;
         number = number / 10 ;
    }

    printf("Sum of digits = %d", b );
    getch();
}

Output of program to sum of digits of a number in c:

program to sum of digits of a number in c
c program to sum the digit of number

 
You can also see other c programs with different categories like, basic programs, operating system, unit conversions, graphics programs, theory of computation, data structure, embedded system and many more.




"Please Do Like Facebook Page and follow us on Twitter so that you can actively participate and develop skills in programming. If you find above post interesting do share the webpage."
This entry was posted in c program and tagged , . Bookmark the permalink.

2 Responses to program to sum of digits of a number in c

  1. Pingback: Program to sum of digits of a number in java - cprogramto.com

  2. Pingback: c program for multiplying digits of number - cprogramto.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>