How to write a C Program to Sum Up Digits of a Number in C Programming Language ?
Solution:
- #include<stdio.h>
- int main()
- {
- int i,divisor,casted,digit,number,sum=0;
- long int m;
- printf("Number of digits in your number : ");
- scanf("%d", &digit);
- int ara[digit];
- printf("\nEnter number : ");
- scanf("%d", &number);
- if(digit==1)
- m=1;
- else if(digit==2)
- m=10;
- else if(digit==3)
- m=100;
- else if(digit==4)
- m=1000;
- else if(digit==5)
- m=10000;
- else if(digit==6)
- m=100000;
- else if(digit==7)
- m=1000000;
- else if(digit==8)
- m=10000000;
- else if(digit==9)
- m=100000000;
- else if(digit==10)
- m=1000000000;
- else if(digit==11)
- m=10000000000;
- for(i=0,divisor=10; i<digit; i++, m=m/10) {
- casted=(int)number/m;
- ara[i]=casted%divisor;
- }
- for(i=0; i<digit; i++){
- sum=sum+ara[i];
- }
- printf("%d\n",sum);
- }
Learn More :
Number
- Find out the perfect number using c program
- Write a c program to find out H.C.F. of two numbers.
- Check the given number is armstrong number or not using c program.
- Write a c program to find largest among three numbers using conditional operator
- FIND OUT GENERIC ROOT OF A NUMBER - C PROGRAM.
- FIND PRIME FACTORS OF A NUMBER USING C PROGRAM
- How To Write a C program that generates two random numbers ?
- Write a C program to find maximum or equal between two numbers ?
- How to Write a C program to find maximum between two numbers ?
- Write a C program to perform math operations on two input whole numbers. The operations are:
- Write a C program to find maximum between three numbers ?
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program to Enter an ODD number between 1 and 49.
- C program acquires keyboard 10 numbers for each of these numbers to determine if it is a first issue, by printing immediately message should at the end, if none of the numbers you entered was a first issue, print an appropriate message.
- C program generates a random number and uses an algorithm to generate 9 other numbers.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Reverse Of Any Digit Number
- C Program To Find The Frequency Of A Number
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print Sum Of n Digit Number
- C Program To Reverse A Number
- C Program To Search A Number Inside The Array
Sum
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Program To Find Sum and Difference Of Two Matrices
- C Program To Print Sum Of n Digit Number
- C Program Finding the sum of Squares using Recursion
- Give me an integer and I will sum it with the previous natural numbers
- C Program to Sum of The First and Last Digit Of 'n' Digit Number
- C Program to Sum of First and Last Digits of a Four-Digit number
- C Program to Sum of digits of a Five Digit Number
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Number and Calculate Sum of it's Digits C Program
Digit
- C Program To Find Reverse Of Any Digit Number
- C Program To Print Sum Of n Digit Number
- C Program To Add Digits Of Entered Number
- C Program Anagrams
- C Program to Sum of The First and Last Digit Of 'n' Digit Number
- C Program to Sum of First and Last Digits of a Four-Digit number
- C Program to Sum of digits of a Five Digit Number
- C Program to Reversing a Five Digit Integer Number
- Input Number and Calculate Sum of it's Digits C Program