programming9
  • Flowcharts
  • Programs
      • Back
      • C Programs
      • C++ Programs
      • Java Programs
      • Python Codes
      • HTML Codes
      • Java Script Codes
      • SQL Codes
  • Tutorials
      • Back
      • Java Tutorials
      • Competitive Programming
      • Python Tutorials
      • C Programming
  • Blog
  • Login

C program to find Sum of Digits of a Positive Integer Number

Details
Written by: RajaSekhar
Category: C Programs
  • Basic C Programs-3
#include<stdio.h>
#include<conio.h>
main()
{
    int r,n,m,sum;
    //clrscr();
    printf("Enter a positive Integer :");
    scanf("%d",&n);
    if(n<0)
        printf("The given number is not +ve Integer");
    else
    {
        sum=0;
        m=n;
        while(m!=0)
        {
            r=m%10;
            sum+=r;
            m/=10;
        }
        printf("The given number  =%d\n",n);
        printf("Sum of digits of the given number is:%d",sum);
    }
}

You can find the flow chart for the above code here.

 OUTPUT:

Enter a positive Integer :456
The given number  =456
Sum of digits of the given number is:15
Previous article: C Program to Find Roots of a Quadratic Equation Prev Next article: Find Two's Complement of a Binary Number Using C programming Next
  • C Program to Sort List of Strings
  • C Program for Optimal Page Replacement Algorithm
  • C Program to Search an Array Element using BINARY SEARCH
  • C Program to Find Area of a Triangle
  • C Program to Print Hello World
  • C Program to Find Biggest of Two Numbers using Ternary
  • C Program to Find Sub String Position in Given String
  • C Program to Implement Structure with Pointers
  • C Program to Evaluate POSTFIX Expression Using Stack
  • C program to Implement BREAK Statement
  • C Program to Find Given Number is Perfect or Not
  • C program to Print Triangle Pattern
  • C Program to Find Length of a String Using STRLEN()
  • C Program to ADD two MATRICES
  • C Program to Implement Doubly Linked List Operations
  • Privacy Policy
  • Cookie Policy
© programming9.com 2026
Back to top