Write C program to calculate product of digits of a number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdio.h> int main() { int n, product=1; // Reading a number from user printf("Enter any number: "); scanf("%d", &n); // Repeat the steps till n becomes 0 while(n != 0) { product = product * (n % 10); // Remove the last digit from n n = n / 10; } printf("Product of digits = %ld", product); return 0; } |
10 July 2019 3022 Written By: Rohit
© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap