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
What is the heap?
List some basic data types in c?
How is actual parameter different from the formal parameter?
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
Explain what is the difference between functions getch() and getche()?
What are the functions to open and close the file in c language?
How will you write a code for accessing the length of an array without assigning it to another variable?
What is the sizeof () operator?
Is c is a middle level language?
What does the && operator do in a program code?
Explain how can you tell whether two strings are the same?
#include
How reliable are floating-point comparisons?
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
What is a void * in c?