Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to sum the digit of each digit

Posted By: Abby Fischer     Category: C Programming     Views: 6114

Write a program to sum the digit of each digit.

Code for Program to sum the digit of each digit in C Programming

#include<stdio.h>
void main()
{
    int a,sum,r;
    sum=0;
    printf("Enter the five digit number :");
    if(scanf("%d",&a)==1)
    {
        for(;a>0;)
        {
            r=a%10;
            sum=sum+r;
            a=a/10;

        }
            printf("answer=%d",sum);
    }
    else
    {
        printf("Enter correct number");
    }
}


=====================OUTPUT=====================
Enter the five digit number :12345
answer=15
  
Share: 


Didn't find what you were looking for? Find more on Program to sum the digit of each digit Or get search suggestion and latest updates.

Abby Fischer
Abby Fischer author of Program to sum the digit of each digit is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!