#include <stdio.h>
#include <stdlib.h>

int add(int i, int j , int k)
{
       while ( i != 0)
     {
     
     
     j = i % 10;
     k = k * j;
     i = i / 10;
     }
      return k;
}

int main ()
{
 int num, num2=1, r;
 int ret=1;
 int i=0;
 
scanf("%d",&num); 
 int answer = add(num , r ,num2);

while (num > 0)
{
 num = answer;
answer = add(num , r ,num2);
if (num < 10)
{
         printf("%d  \n ",answer);
         system("PAUSE");
          return 0;
        break;
        }
}
 printf("%d  \n ",answer);
 system("PAUSE");
 return 0;

}

Sorry if i didn't give more information it supposed to multiply digits of a number

All through this program...What's the value of r?

It supposed automatically be j. But i already solved the problem by entering if condition.

Member Avatar for MonsieurPointer

I think the issue is with this line:

i = i / 10;

Since i is an integer, and you are performing a division, it will cast i / 10 back into an integer. For example, if i / 10 resulted in 0.1, then i will equal 0, because 0.1 will be casted as 0 when defined as an integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.