C program to print product of the digits of the number

Solution with out using functions(Using For Loop)

Solution with out using functions(Using While Loop)

Solution using functions without passing arguments

Solution using functions and by passing arguments



C program to print product of the digits of the number(Using For Loop)

Solution : Without using function
Program/Source Code

#include <stdio.h>

int main()
{
    int n,p=1,d;
    printf("Enter any no ");
    scanf("%d",&n);
    for(;n>0;)
    {
        d=n%10;
        p=p*d;
        n=n/10;
    }
    printf("Product of digits = %d",p);
    return 0;
}

Output:

Enter any no 1234
Product of digits = 24



C program to print product of the digits of the number(Using While Loop)

Solution : Without using function
Program/Source Code

#include <stdio.h>

int main()
{
    int n,p=1,d;
    printf("Enter any no ");
    scanf("%d",&n);
    while(n>0)
    {
        d=n%10;
        p=p*d;
        n=n/10;
    }
    printf("Product of digits = %d",p);
    return 0;
}

Output:

Enter any no 25
Product of digits = 10



C program to print product of the digits of the number

Solution : Using function Without Passing Arguments
Program/Source Code

#include <stdio.h>
void check()
{
    int n,p=1,d;
    printf("Enter any no ");
    scanf("%d",&n);
    while(n>0)
    {
        d=n%10;
        p=p*d;
        n=n/10;
    }
    printf("Product of digits = %d",p);
}

int main()
{
    check();
    return 0;
}

Output:

Enter any no 145
Product of digits = 20



C program to print product of the digits of the number

Solution : Using function Passing Arguments
Program/Source Code

#include <stdio.h>
void check(int n)
{
    int p=1,d;
    while(n>0)
    {
        d=n%10;
        p=p*d;
        n=n/10;
    }
    printf("Product of digits = %d",p);
}

int main()
{
    int n;
    printf("Enter any no ");
    scanf("%d",&n);
    check(n);
    return 0;
}

Output:

Enter any no 256
Product of digits = 60

Previous:

Next:

C Language Programming Tutorial

C Language Tutorial Home    Introduction to C Language     Tokens     If Condition     goto statement and Labelname     Switch Statements     For loop     While Loop    Do while loop     break and continue    Functions    Recursion    Inbuild Functions    Storage Classes    Preprocessor    Arrays    Pointers     Structures and Unions    File Handling     Projects

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions
C Programs
C++ Programs