Program to find sum of individual digits of entered number

1 year ago Admin 0

Find sum of individual digits of entered number

This article illustrates the concept how to find sum of individual digits of entered number in c/c++.

find sum of individual digits of entered number

Here is the source code and output of both the programs.

C Programming language

Program


#include<stdio.h>
#include<conio.h>
void main()
{
 int num,res=0,rem;
 clrscr();
 printf("Enter number :- ");
 scanf("%d",&num);
 while(num!=0)
  {
   rem=num%10;
   res=res+rem;
   num=num/10;
  }
 printf("Sum of individual digit of number is:- %d",res);
 getch();
}

After successfully compiling and executing the above C program,output is:-

find sum of individual digits of entered number


C++ Programming language

Program


#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int num,res=0,rem;
 cout<<"Enter number :- ";
 cin>>num;
 while(num!=0)
  {
   rem=num%10;
   res=res+rem;
   num=num/10;
  }
 cout<<"Sum of individual digit of number is:- "<<res;
 getch();
}

After successfully compiling and executing the above C++ program,output is:-

find sum of individual digits of entered number


Comment below if you are facing any problem or you find any error in the above program and also subscribe to our newsletter for more updates.


Read more c/c++ Programs published by snapcout:-

Program to find hcf of two numbers
Program to find lcm of two numbers
Program to find maximum of given number
Program to count number of digit in an integer
Program to find factors of a number


About article

Written By:- Admin

Published on:- 05/08/2018

Published By:- Snapcout


Don't forget to share the article if you like it:-