how to find sum of digits in C?

Answer Posted / pankaj khaitan

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

Is This Answer Correct ?    40 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a function and a method in c?

560


What are c preprocessors?

679


What are the scope of static variables?

601


What is optimization in c?

568


Explain about the constants which help in debugging?

856






What are the keywords in c?

643


Why C language is a procedural language?

623


Explain how do you list a file’s date and time?

621


Can a pointer point to null?

589


Give me the code of in-order recursive and non-recursive.

886


What are the advantages of union?

628


What is the heap in c?

645


What does & mean in scanf?

604


What are c header files?

581


Explain what are the different file extensions involved when programming in c?

633