Discussion Forums

New User? Please read instructions!

Need C program to sum up all individual digits  

  RSS

thiyagarajan
Eminent Member
Joined: 4 months  ago
Posts: 26
27/01/2017 9:34 am  

Need C program to sum up all individual digits


ReplyQuote
admin
Eminent Member
Joined: 5 years  ago
Posts: 26
31/01/2017 11:20 am  

Hi Thiyagarajan, Please use below C program to sum up all individual digits of a given number.

 

#include <stdio.h>

int main()

{

   int n, sum = 0, rem; 

   printf("Please enter an integer\n");

   scanf("%d",&n);

 

   while(n != 0)

   {

      rem = n % 10;

      sum = sum + rem;

      n = n / 10;

   }

   printf("Sum of all individual digits of an entered number is %d\n",sum);

   return 0;

}

Edited: 4 months  ago

ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!