Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number

#include<stdio.h>
#include<conio.h>

void main()
{
int no,r,pt=1;
clrscr();
printf("Enter a no:");
scanf("%d",&no);
while(no>0)
{
r=no%10;
pt=pt*r;
no=no/10;
}
printf("Product of Digits= %d",pt);
getch();
}

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. #include stdio.h>
    int main()
    { int k,n,p,r,prod1=1,prod=1,sum=0,sum1=0,i=0,digit;
    printf("\nEnter a non negative integer: ");
    scanf("%d",&n);
    if (n<10)
    {
    prod=n;
    sum=n;
    digit=1;
    }
    else
    {
    do
    {
    k=n%10;
    p=n-k;
    r=p/10;
    prod1=prod1*k;
    sum1=sum1+k;
    n=r;
    i++;
    }
    while(r>9);
    prod=prod1*r;
    sum=sum1+r;
    digit=i+1;
    }
    printf("\n\nproduct of digit: %d\n\nsum of digit: %d\n\nnumber of digit: %d\n",prod,sum,digit);
    return 0;
    }

    ReplyDelete

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number