Computer Science, asked by davendratiwari7523, 3 months ago

write a program to stored
a four digit
number find the sum and product of all
the four digits​

Answers

Answered by SparklyGeogony
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