Skip to content

Instantly share code, notes, and snippets.

@ugandapinik
Created July 21, 2016 05:48
Show Gist options
  • Save ugandapinik/979764a886146f7f60cec72c91f1ffbc to your computer and use it in GitHub Desktop.
Save ugandapinik/979764a886146f7f60cec72c91f1ffbc to your computer and use it in GitHub Desktop.
C program to accept an integer & find the sum of its digits
//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