how to find sum of digits in C?

Answer Posted / bhagwat

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}

Is This Answer Correct ?    53 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the bubble sort algorithm.

646


Explain what is the purpose of "extern" keyword in a function declaration?

623


How can I avoid the abort, retry, fail messages?

663


What is the use of structure padding in c?

563


Define macros.

785






What does it mean when the linker says that _end is undefined?

635


I need testPalindrome and removeSpace #include #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

2214


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

810


Why is this loop always executing once?

617


Can you assign a different address to an array tag?

702


What is line in c preprocessor?

616


What is the purpose of type declarations?

681


Explain pointers in c programming?

636


How do you search data in a data file using random access method?

834


Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

1468