C Language

May 28, 2023

How to define a product in C Language

Program to use define a product in C Language


#include <stdio.h&t;
int main()
{
    int n, prod = 1, rem;
    printf("enter a number : ");
    scanf("%d", &n);
    while (n > 0)
    {
        rem = n % 10;
        prod *= rem;
        n /= 10;
    }
    printf("product of digits = %d\n", prod);
    return 0;
}

output


enter a number :55
product of digits = 25

by : Nadeem Khan

Quick Summary:

इसमें rem=n%10 जो value देगे reminder होगा 55 का rem 5 होगा फिर prod*=rem होगा 1*5 =5 होगा उसके बाद n/10 भाग करने पर 5 आएगा दोबारा लूप चलेगा जब तक condition जब तक false हो