Friday, October 14, 2011

Write a C program to find the sum, multiplication, division, subtraction of individual digits of a positive integer.

#include //This is include information about standard library
main() //User define function
{
int n,a=0,b,c=1; //int funcion which takes all integer values in the program
float d=1,e=0; //float function which takes all float values in the program
printf ("Enter a number(contains atleast two digits):"); //printing statement
scanf ("%d",&n); //attaching the user input to the variable
while (n!=0)
{
b=n%10; // % of given number with 10
a=a+b; //summation of the digits in the integer
c=c*b; //multiplication of th digits in the integer
d=b/d; //division of the digits in the integer
e=b-e; //substraction of the digits in the integer
n=n/10;
}
printf ("summation of the digits in the number :%d\n",a); //prints summation of the digits in the given integer
printf ("multiplication of the digits in the number :%d\n",c); //prints multiplication of th digits in the given integer
printf ("division of the digits in the number :%f\n",d); //prints division of the digits in the given integer
printf ("substraction of the digits in the number :%f\n",e); //substraction of the digits in the given integer
}

No comments:

Post a Comment