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 uses of .net

1277


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

1907


What is sizeof in c?

571


What is a buffer in c?

575


Why does notstrcat(string, "!");Work?

643






Explain what is wrong with this program statement? Void = 10;

765


Explain what is the purpose of "extern" keyword in a function declaration?

623


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

675


What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers

680


Explain a file operation in C with an example.

663


How is null defined in c?

652


What is the full form of getch?

585


Can you write a programmer for FACTORIAL using recursion?

614


Tell me what is the purpose of 'register' keyword in c language?

619


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

626