Friday, 14 October 2016

Write a C Program to Add Digits & Multiplication of a number.


3b.c
Aim:-b)Write a C Program to Add Digits & Multiplication of a number.

Program:-

#include<stdio.h>
int main()
{
      int num,sum=0,r,prod=1;
      printf("Enter a number: ");
      scanf("%d",&num);
     while(num>0)
            {
                   r=num%10;
                   num=num/10;
                   sum=sum+r;
                   prod=prod*r;
           }
  printf("\nSum of digits of number:  %d",sum);
  printf("\nProduct of digits of number: %d",prod);

}

1 comment: