Discussion Forums

New User? Please read instructions!

Need C program to sum up all individual digits  

  RSS

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

Need C program to sum up all individual digits


ReplyQuote
admin
Eminent Member Admin
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: 10 months  ago

ReplyQuote
  
Working

Please Login or Register






Share this website !!!
Facebook Twitter Linkedin