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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a c program for swapping two strings using pointer

2566


Dont ansi function prototypes render lint obsolete?

1061


What is a struct c#?

998


What is the difference between fread buffer() and fwrite buffer()?

1105


What does a pointer variable always consist of?

1039


What is output redirection?

1164


what do you mean by inline function in C?

1006


What are void pointers in c?

963


Add Two Numbers Without Using the Addition Operator

767


How can I make sure that my program is the only one accessing a file?

1189


What are multidimensional arrays?

1060


How many bytes are occupied by near, far and huge pointers (dos)?

1115


What are actual arguments?

1044


What are the different types of constants?

1020


Write a program to print "hello world" without using a semicolon?

1003