Function to find addition of digits of five digit number without using recursion.
#include <stdio.h>
int convert(int a)
{
int value, num, n=0, j=10, i;
value=a;
for(i=1;i<=5;i++)
{
value=value%10;
num=value;
n=n+num;
value=a/j;
j*=10;
}
return n;
}
int main()
{
int a, sum;
printf("Enter the 5 Digit number\n");
scanf("%d", &a);
sum=convert(a);
printf("The sum of number is \n %d", sum);
return 0;
}
Comments
Post a Comment