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
  • Evaluate Algebraic Expression (ax+b)/(ax-b)
  • Fizz Buzz Implementation in C
  • C Program to Compare Two Strings using strcmp()
  • C Program to Find Sum of Odd Integers
  • C Program for Fibonacci Series using While Loop
  • C Program to Calculate Sum of Even Values in an Array
  • C Program to Convert Temperature from Degree Centigrade to Fahrenheit
  • C Program to convert Celsius to Fahrenheit
  • C Program to Implement Doubly Linked List Operations
  • C Program to Sort an Array using SELECTION SORT
  • C Program for Matrix Multiplication
  • C Program to Implement STACK Operations Using Pointers
  • C Program for Circumference of a Circle
  • C Program to Find Address Locations of Variables
  • C Program to Print Elements of Array Using Pointers
  • Privacy Policy
  • Cookie Policy
© programming9.com 2026
Back to top