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 Example to Initialize Structure Variable
  • C Program to Calculate Sum of Odd Values in an Array
  • C Program for String Concatenation without using strcat()
  • Swapping of Two Numbers Using Call By Reference in C
  • Implementation of Stack Using Array in C
  • C Program for Implementation of Predictive Parser
  • C Program to Simulate PRIORITY CPU Scheduling Algorithm
  • C Program to Find Area and Circumference of a circle.
  • C Program to Find Area of a Square
  • C Program for Quick Sort
  • C Program to Implement SHELL SORT
  • C Program to Find Biggest among Three Numbers
  • C Program to Calculate Sum of Even Values in an Array
  • C program to Print Triangle Pattern
  • C Program to Check Whether a Number is PALINDROME or Not
  • Privacy Policy
  • Cookie Policy
© programming9.com 2026
Back to top