- Hello World c
- C Program to Add Two Numbers
- Area of Triangle C
- Odd or Even C
- Write a C program to find the sum of digitis of a given number
- Write a C program to find the maximum of three numbers
- Write a C program to swap two number using third variable
- Write a C program to swap to numbers without using third variable
- Write a C program to calculate the area of circle
- Write a C program to calculate the Binomial Coefficient (nCr)
- Write a C program to calculate the permutations (nPr)
- Write a C program to reverse the number
- Write a c program to check the given number is palindrome or not
- Write a c program to check the given number prime or not
- Write a c program to check the given number is armstrong or not
- Write a C program to generate all Armstrong number till n
- Write a program to check given number perfect or not
- Write a C program to check alphabet is vowel or consonant
- Write C program to calculates the factorial of a given number
- Write a C program generate and prints the Fibonacci series up to a user-defined limit
- Write a C program to calculate the nth number in the Fibonacci series using recursion
- Write a C program to find the maximum element in the array
- Write a C program to find the minimum element in the array
- Write a C program to search the element using linear search technique
- Write a C program to Insert element in array

```
#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter the number : ");
scanf("%d", &n);
while (n != 0){
int last_digit = n % 10;
sum += last_digit;
n = n / 10; // remove last digit
}
printf("Sum of digits : %d", sum);
}
```

Above C code takes the number as input from the user and calculate the sum of the digits. It first initializes the variable **‘sum’** to 0. Then prints or prompts the user to enter an integer using the **printf** function and reads the input using the **scanf** function.

The code entters a while loop that loop continues until the value of **n** becomes 0. In each iteration of the loop, it computes the last digit of 'n' using the **modulo operator** and adds it to **‘sum’**. It then removes the last digit from ‘n’ by dividing it by 10.

Finally, it prints the sum of digits using the **printf()** function.

- Initialize variable ‘n’ and ‘sum’ to 0.
- Prompt / print message to the user to enter an integer ‘n’ using printf() and read the input using
**scanf()**. - while ‘n’ is not equal to 0, repeate the followig steps:

a. Compute the last digit of ‘n’ using the modulo operator andd assign it to a variable ‘last_digit’.

b. Add “last_digit' to ‘sum’.

c. Remove the last digit from ‘n’ by dividing it by 10. - Print the value of ‘sum’ using printf().
- Exit

```
1. Set n = 0
2. Set sum = 0
3. Display "Enter the number : "
4. Read integer n from user using scanf
5. While n is not equal to 0, repeat the following:
a. Set last_digit = n % 10
b. Set sum = sum + last_digit
c. Set n = n / 10
6. Display "Sum of digits : " followed by the value of sum using printf
```

Learn More Do More. Happy Coding!.

🖤 0

Buy me coffee ☕

## Comments

Oops!