145k views
5 votes
Plzz help me with this question.........

Write a program to input a number find the sum of digits and the number of digits. Display the output

sample input - 7359
sample digits - 24
number of digits - 4​

2 Answers

4 votes

Answer Using Java :-

import java.util.*;

public class Digit

{

public static void main(String args[ ] )

{

Scanner in=new Scanner (System.in)

System.out.print("Enter a number: ");

int n = in.nextInt();

int sum = 0, count = 0;

while (n!=0)

{

int d = n % 10;

sum + = d;

count++;

n /= 10;

}

System.out.println("Sum of digits=" +sum);

System.out.println("Number of digits=" +count);

}

}

User Kaediil
by
4.5k points
3 votes

Answer:

str = input("Enter a number: ")

sum = 0

for c in str:

sum = sum + int(c)

print("Sample input - {}".format(str))

print("Sum of digits - {}".format(sum))

print("Number of digits - {}".format(len(str)))

Step-by-step explanation:

That's python. Was that what you were looking for?

User PaladiN
by
4.6k points