write a program to sum of its digit with using control
structure or with out using loop. for ex: let the number is
25634 then answer will be=2+5+6+3+4=20
Answers were Sorted based on User's Feedback
Answer / alex r.
// without loop
// for digit in DEC
#include <stdio.h>
int sum(int digit)
{
if (digit%10 != digit)
return digit%10 + sum(digit/10);
return digit;
}
int main(void)
{
int digit = 25634;
printf("\nSum:%d", sum(digit));
return 0;
}
| Is This Answer Correct ? | 15 Yes | 7 No |
Answer / lalabs
// assume that num is non-negative.
int sum_digits_recursive ( int num )
{
if ( num == 0 ) return 0;
return (num % 10 + sum_digits_recursive ( num / 10 ));
}
| Is This Answer Correct ? | 6 Yes | 1 No |
Answer / rama krishna sidhartha
#include <stdio.h>
#include<conio.h>
void main()
{
int s=0,c,n;
clrscr();
printf("\n ENTER A VALUE : ");
scanf("%d",&n);
while(n>0)
{
c=n%10;
s=s+c;
n=n/10;
}
printf("\n THE SUM OF INDIVIDUAL DIGITS : %d",s);
getch();
}
| Is This Answer Correct ? | 10 Yes | 10 No |
Answer / thiruapthi rao
// mainlogic
while(number>0)
{
remainder=number%10;
sum=sum+remainder;
number=number/10;
}
/*
number=123
sum=1+2+3=6
*/
| Is This Answer Correct ? | 0 Yes | 1 No |
how to find the largest element of array without using relational operater?
what does ‘segmentation violation’ mean?
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a
What is wrong with this program statement? void = 10;
what is structuer?
consagous technology placement paper
what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }
Explain what are the __date__ and __time__ preprocessor commands?
Please provide question papers of NATIONAL INFORMATICS CENTRE for Scientific officer
explain what is fifo?
How can variables be characterized?
Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them in a pair hg fe dc ba.