Write a C program to print sum of digits enter by user


Introduction

Write a C program to print sum of digits enter by user


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>

int main()
{
    int num, total;

    //Reading number
    printf("Enter any number: ");
    scanf("%d", &num);

    //Adding sum of digit in total variable
    for(total = 0; num > 0; num = num/10)
        total = total + (num%10);

    //Printing sum of digit
    printf("Sum of digits: %d", total);

    return 0;
}

Result

C language

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.