Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



write a program to sum of its digit with using control structure or with out using loop. for ex: l..

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

write a program to sum of its digit with using control structure or with out using loop. for ex: l..

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

write a program to sum of its digit with using control structure or with out using loop. for ex: l..

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

write a program to sum of its digit with using control structure or with out using loop. for ex: l..

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

Post New Answer

More C Interview Questions

Find greatest number out of 10 number without using loop.

5 Answers   TCS,


Is void a keyword in c?

0 Answers  


pgm to find middle element of linklist(in efficent manner)

4 Answers   Huawei,


c program for searching a student details among 10 student details

0 Answers  


how can you print&scan anything using just one character? :) HINT: printf,scanf similer

2 Answers  


main() { float a=8.8; double b=8.8; if(a==b) printf("Equal"); else printf("not equal"); getch(); } what is the output? with reason

6 Answers   CSC,


Why ca not I do something like this?

0 Answers  


How can I call fortran?

0 Answers  


What is the time and space complexities of merge sort and when is it preferred over quick sort?

0 Answers   Amazon,


how can f be used for both float and double arguments in printf? Are not they different types?

0 Answers  


Differentiate between declaring a variable and defining a variable?

0 Answers  


What does extern mean in a function declaration?

4 Answers  


Categories