Created
July 21, 2016 05:48
-
-
Save wohhie/979764a886146f7f60cec72c91f1ffbc to your computer and use it in GitHub Desktop.
C program to accept an integer & find the sum of its digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//C program to accept an integer & find the sum of its digits | |
#include <stdio.h> | |
int main() { | |
int num, digit; | |
int sum = 0; | |
int temp; | |
printf("Enter Number : "); //123 | |
scanf("%d", &num); | |
temp = num; | |
while (num > 0) { | |
digit = num % 10; | |
sum = sum + digit; | |
num /= 10; | |
} | |
printf("\n"); | |
printf("Given Number is: ", num); | |
printf("\nSum of digit: %d = %d", temp, sum); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment