Jun 11, 2020

C Program to find product of digits of a number

Ex: write a C program to print product of digits of a number. How to write a C program to print product of digits of a number. C program to find product of digits of number.


Input from user:

Enter the number: 12345

Expected output:

Product of given number is: 120





Step by step logic of the given program:

1. Accept input (number) from user.

2. Use one while loop to check given number is greater than 0 or not.

3. Loop will iterate if number is greater than 0.

4. Inside the while loop product of digit calculate using...

z=no%10;
product*=z;
no=no/10;

5. Print product on the output screen.





Program:

#include<stdio.h>
int main()
{
int no,z;
long long int product=1ll;

printf("Enter the number\n");
scanf("%d",&no);

while(no!=0)
{
z=no%10;
product*=z;
no=no/10;
}
printf("product of given number is:%lld",product);

return 0;

}


Above prgram shows the following output:



Share This:    Facebook Twitter

0 comments:

Post a Comment

If you have any doubts, please discuss here...