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 is the heap?

1258


List some basic data types in c?

1082


How is actual parameter different from the formal parameter?

1062


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

2130


Explain what is the difference between functions getch() and getche()?

1112


What are the functions to open and close the file in c language?

1085


How will you write a code for accessing the length of an array without assigning it to another variable?

1094


What is the sizeof () operator?

1134


Is c is a middle level language?

1126


What does the && operator do in a program code?

1282


Explain how can you tell whether two strings are the same?

1077


#include { printf("Hello"); } how compile time affects when we add additional header file .

1942


How reliable are floating-point comparisons?

1151


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

1264


What is a void * in c?

1136