Powered By Blogger

Feb 11, 2025

9. Sum of Digits

 #include <stdio.h>

int main() {

    int num, sum = 0, rem;

    printf("Enter a number: ");

    scanf("%d", &num);

    while(num != 0) {

        rem = num % 10;

        sum += rem;

        num /= 10;

    }

    printf("Sum of digits: %d\n", sum);

    return 0;

}


No comments:

Post a Comment

Featured Post

Data Analysis

    What is data analysis and its significance?   Data analysis is the process of collecting, transforming, and organizing data to dr...

Popular Posts