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 are c identifiers?
What is the meaning of && in c?
Explain what is the benefit of using an enum rather than a #define constant?
What do you mean by dynamic memory allocation in c? What functions are used?
Did c have any year 2000 problems?
What is wild pointer in c with example?
What is gets() function?
Why do we need volatile in c?
What is string function in c?
When should the volatile modifier be used?
Explain how do you generate random numbers in c?
How do you determine whether to use a stream function or a low-level function?
Is this program statement valid? INT = 10.50;
Explain what’s a signal? Explain what do I use signals for?
Explain what are the standard predefined macros?