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 gat the digt sum of a number (et. 15=
>1+5=6)

Answer Posted / santhosh kumar

#include<stdio.h>
#include<string.h>

int main ()
{
char no[100];
char num[2];
int i;
int length = 0;
int sum = 0;

memset(num, 0, 2);
printf("Enter the number: ");
gets(no);
length = strlen(no);

for(i=0; i<length; i++)
{
num[0] = no[i];
sum += atoi(num);
}

printf("Sum = %d", sum);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are c identifiers?

1102


What is the meaning of && in c?

1025


Explain what is the benefit of using an enum rather than a #define constant?

1227


What do you mean by dynamic memory allocation in c? What functions are used?

1169


Did c have any year 2000 problems?

1113


What is wild pointer in c with example?

1068


What is gets() function?

1143


Why do we need volatile in c?

1183


What is string function in c?

993


When should the volatile modifier be used?

1191


Explain how do you generate random numbers in c?

1090


How do you determine whether to use a stream function or a low-level function?

1132


Is this program statement valid? INT = 10.50;

1167


Explain what’s a signal? Explain what do I use signals for?

1169


Explain what are the standard predefined macros?

1123