how to find sum of digits in C?

Answer Posted / anil kumar nahak

void main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the Purpose of 'extern' keyword in a function declaration?

645


Why we use void main in c?

590


How can I find the modification date and time of a file?

596


What is dynamic variable in c?

559


Does c have function or method?

585






Can a function argument have default value?

666


what are bit fields in c?

599


How can I run c program?

677


What is function prototype?

607


Can we change the value of static variable in c?

556


How can I insert or delete a line (or record) in the middle of a file?

568


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1345


What is the difference between void main and main in c?

619


What is console in c language?

599


What is spark map function?

578