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

Explain logical errors? Compare with syntax errors.

618


Why do we use main function?

626


can we have joblib in a proc ?

1650


Describe the steps to insert data into a singly linked list.

613


Which header file should you include if you are to develop a function which can accept variable number of arguments?

795






how is the examination pattern?

1587


Why do we use namespace feature?

573


Hai what is the different types of versions and their differences

1482


List some applications of c programming language?

539


What is the use of getch ()?

620


What is 2c dna?

596


Compare array data type to pointer data type

592


Explain how do you list files in a directory?

610


ATM machine and railway reservation class/object diagram

4792


why do some people write if(0 == x) instead of if(x == 0)?

647