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 difference between c &c++?
Explain the red-black trees?
What is the use of define in c?
Explain data types & how many data types supported by c?
Can true be a variable name in c?
Which is the memory area not included in C program? give the reason
any "C" function by default returns an a) int value b) float value c) char value d) a & b
Tell us the use of fflush() function in c language?
What is #include in c?
What is static memory allocation?
How can you increase the size of a dynamically allocated array?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
How variables are declared in c?
Differentiate between null and void pointers.
If the size of int data type is two bytes, what is the range of signed int data type?