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 difference between c &c++?

647


Explain the red-black trees?

609


What is the use of define in c?

597


Explain data types & how many data types supported by c?

586


Can true be a variable name in c?

559






Which is the memory area not included in C program? give the reason

1508


any "C" function by default returns an a) int value b) float value c) char value d) a & b

667


Tell us the use of fflush() function in c language?

639


What is #include in c?

600


What is static memory allocation?

609


How can you increase the size of a dynamically allocated array?

642


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

610


How variables are declared in c?

571


Differentiate between null and void pointers.

633


If the size of int data type is two bytes, what is the range of signed int data type?

594