SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to add the digits of a number using for loop
C program to add the digits of a number using for loop
Output:
Enter the number to add its digits:
1234
The sum of digits of 1234 is 10
Implementation:
#include
int main(void) { int n,copy; int digitsum=0; printf("Enter the number to add its digits:\n"); scanf("%d",&n); copy=n; for(;n;digitsum+=(n%10),n/=10); printf("The sum of digits in %d is %d",copy,digitsum); return 0; }
PREVIOUS
NEXT
HOME