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: |
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 |