write a program to stored
a four digit
number find the sum and product of all
the four digits
Answers
Answered by
21
Answer:
Lets say n is that 4 digit number.
while(n>0)
{
//isolating the digit in the 10^k th place
i=i%10;
//adding & storing in a variable called sum
sum+=i;
//trying to get the digit in 10^x th place to 10^(x-1) th place
n/=10;
}
The variable ‘sum’ will have the answer.This works for any number of digits,not just 4 digits(provided it is a positive number)
@itzunique!
Similar questions
Social Sciences,
1 month ago
Hindi,
1 month ago
Science,
1 month ago
Social Sciences,
3 months ago
Math,
3 months ago
Physics,
9 months ago
English,
9 months ago