how to find sum of digits in C?

Answer Posted / deepak upadhyay

#include<stdio.h>
void main()
{
int num,a,b,c,d,e,sum;
printf("enter the num");
scanf("%d",&num);
a=num%10;
b=((num%100)-a)/10;
c=((num%1000)-(num%100))/100;
d=((num%10000)-(num%1000))/1000;
e=((num%100000)-(num%10000))/10000;
sum=a+b+c+d+e;
printf("\n1's place= %d \n10's place= %d \n100's
place= %d \n1000's place= %d \n10000's place=
%d",a,b,c,d,e);
printf("\nsum=%d",sum);
}

Is This Answer Correct ?    1 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are the facialities provided by you after the selection of the student.

1666


What is difference between && and & in c?

611


When can you use a pointer with a function?

578


Was 2000 a leap year?

642


Can an array be an Ivalue?

676






a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

887


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

723


When would you use a pointer to a function?

595


Write programs for String Reversal & Palindrome check

603


Explain built-in function?

605


What are the types of pointers?

610


code for quick sort?

1628


Explain modulus operator.

605


#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }

676


What does %p mean?

607