how to find sum of digits in C?

Answer Posted / giri

#include <stdio.h>
#include <conio.h>

void main()
{
int sum=0, num, mul=1;
printf("Enter the number");
scanf("%d", &num);

while(num)
{
sum = sum + ((num%10)*mul);
num = num/10;
mul = mul * 10;
}

printf("Sum is %d", sum);
}

Is This Answer Correct ?    6 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Here is a good puzzle: how do you write a program which produces its own source code as output?

602


Hi can anyone tell what is a start up code?

1620


Is c# a good language?

614


In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

1385


Differentiate Source Codes from Object Codes

828






What are the types of i/o functions?

685


Why doesnt that code work?

604


hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...

1451


Explain pointers in c programming?

640


Does c have function or method?

596


Is linux written in c?

603


Compare and contrast compilers from interpreters.

684


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

3152


Why is this loop always executing once?

619


Explain the difference between call by value and call by reference in c language?

651