write a program to input an integer and find the sum of its digits
Answers
Answered by
3
The program output is also shown below.
* C program to accept an integer & find the sum of its digits.
#include <stdio.h>
{
long num, temp, digit, sum = 0;
printf("Enter the number \n");
scanf("%ld", &num);
temp = num;
while (num > 0)
More item
Amanmishra813:
Kyu
Answered by
4
CODE
import java.util.*;
class Sum_digits
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int d=0;
int s=0;
while(n>0)
{
d=n%10;
s=s+d;
n=n/10;
}
System.out.println("The sum of the digits = "+s);
}
}
----------------------------------------------------
OUTPUT
Enter a number
561
The sum of the digits = 12
Hope it helps :-)
______________________________________________________________________
Similar questions