if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')

Answer Posted / jegadeesh

#include<stdio.h>
void main()
{
int i,j;
scanf("%d",&i);
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}

//the above will print result as 6 if given as 12345 since
1+2+3+4+5=15 and proceeding 1+5 we get as 6.....
is this an apt answer...

Is This Answer Correct ?    11 Yes 36 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is structure padding done in c?

637


What is a constant and types of constants in c?

596


Why does this code crash?

610


Is file a keyword in c?

492


What do you mean by c what are the main characteristics of c language?

562






c program for searching a student details among 10 student details

1646


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1116


What is the usage of the pointer in c?

596


List some basic data types in c?

553


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1444


What is the value of c?

566


Differentiate between #include<...> and #include '...'

613


What is difference between structure and union with example?

586


How can I pad a string to a known length?

605


What are the advantage of c language?

544