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)
{
if((i%9)==0)
printf("The sum of digit is 9");
else
{
j=i%9;
printf("%d",j);
}
}
else
{
printf("The sum of digit is ",i);
}

}

//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 answer u are looking...

Is This Answer Correct ?    9 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

any "C" function by default returns an a) int value b) float value c) char value d) a & b

656


Write a C++ program to generate 10 integer numbers between - 1000 and 1000, then store the summation of the odd positive numbers in variable call it sum_pos, then find the maximum digit in this variable regardless of its digits length.

1556


Explain what are the different data types in c?

743


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

616


How many levels of indirection in pointers can you have in a single declaration?

585






What is the use of extern in c?

635


What do you mean by invalid pointer arithmetic?

625


When c language was developed?

626


Is malloc memset faster than calloc?

603


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

1614


What is an auto keyword in c?

631


Tell me can the size of an array be declared at runtime?

589


write a c program in such a way that if we enter the today date the output should be next day's date.

1674


Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

1880


What is the use of sizeof () in c?

545