Showing posts with label sum of digits in c++. Show all posts
Showing posts with label sum of digits in c++. Show all posts

Sunday, May 22, 2016

Sum of Digits in C

A simple program that I wrote using C language as my programming language that will ask the user to give a number and then our program will add the sum of digits in a given number by our user. The code is very to understand.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


#include <stdio.h>
#include <stdlib.h>

int main()
{
   int number=0, process=0, sum = 0, remainder=0;

   printf("\n\n");
   printf("\t Sum of Digits in C ");
   printf("\n\n");
   printf("Kindly give a number : ");
   scanf("%d", &number);

   process = number;

   while (process != 0)
   {
      remainder = (process % 10);
      sum = sum  + remainder;
      process = (process / 10);
   }

   printf("\n\n");
   printf("The total sum of digits is %d.", sum);
   printf("\n\n");
   printf("End of Program");
   printf("\n\n");
   system("pause");
}