20_10

Write a C program to accept an integer & find the sum of its digits.

Source code:

 //Write a C program to accept an integer & find the sum of its digits

#include <stdio.h>

int main()

{

int num, sum = 0;

printf("Enter a number: ");

scanf("%d", &num); 

int digit, temp;

temp = num;

while (num > 0)

{

digit = num % 10;

sum = sum + digit;

num /= 10;

}

printf("Sum of the digits %d = %d", temp, sum);

return 0;

}

Output:

C program to accept an integer & find the sum of its digits


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...