Write C program to calculate product of digits of a number


Introduction

Write C program to calculate product of digits of a number.


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

 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;
}

Result

C language

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.