## INDEX

### Write a c program to find out sum of digit of given number

Code 1:
1. C program to add digits of a number
2. C program for sum of digits of a number
3. C program to calculate sum of digits

#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of digits of number:  %d",sum);
return 0;
}

Sample output:
Enter a number: 123
Sum of digits of number:  6

Code 2:
1. Sum of digits of a number in c using for loop

#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);

for(;num!=0;num=num/10){
r=num%10;
sum=sum+r;
}
printf("Sum of digits of number:  %d",sum);
return 0;
}

Sample output:
Enter a number: 567
Sum of digits of number:  18

Code 3:
1. Sum of digits in c using recursion

#include<stdio.h>

int getSum(int);
int main(){
int num,sum;
printf("Enter a number: ");
scanf("%d",&num);

sum = getSum(num);

printf("Sum of digits of number:  %d",sum);
return 0;
}

int getSum(int num){

static int sum =0,r;

if(num!=0){
r=num%10;
sum=sum+r;
getSum(num/10);
}

return sum;
}

Sample output:
Enter a number: 45
Sum of digits of number:  9

1. good program

IT'S LOT OF

2. thanx dude

3. please tell me how to write a programme to generate Fibonacci series using recursion

4. Sir, Plz tell me When there is the requirement to see the numbers from 1 to 2000 using for...loop it displays one screen i want to see it using pagewise. what is the procedure.

Kamala kanta Rath

5. cool but each information is necessary to us so upload every one programme//

6. explain me the logic

7. what is the use of while loop here?

8. Can any body tell me if i want to sum of a digit of a fraction no then what shal i hav to do?
E.g 123456.789
1+2+3+4+5+6+7+8+9=45

9. please tell me how to write c program to find second largest digit of given number using function

10. literally..a when ever i see his answers, i find myself nothing....his logic is too good..

11. Thanks a lots..its help me as a beginner on programming.

12. Really appreciate ur work !
Thanks

13. Check your programme in which u used while loop:while (num) it should be while (num!=0).

14. It is correct.
Every non-zero value is treated as true.
So the loop iterates till num reaches 0.

15. can anyone please help me write a code to calculate the sum of the input given number using 3 LOOPING STATEMENT??? thank you!

16. code1 is not working for six digit number like123456 (producing garbage value)...can anyone help me

17. pls say why we are using while loop here.....................

18. how to print diagonal elements of 3*3 matrix

19. hw to print sum of integers in the range 1 to 100 till it encounters -1. print all sum of numbers before it encounters -1.

20. Must!! Urget. Can anyone??

WAP to accept the value under 100 and multiply the digit till you get the result in single digit.

Ex: 28, 2*8=16 =1*6 = 6

21. This comment has been removed by the author.

1. This comment has been removed by the author.

2. This comment has been removed by the author.

1. You can find One more Solution in this link One More Solution

23. plz tell me the program to add two numbers each of 100 digits.

24. plz tell me the program to add two numbers each of 100 digits.

25. plz tell me the program to add two numbers each of 100 digits.

26. Int I=1,j=1,r;
While(I<=12)
{ while(j<=12)
{
r=pow(I,j);
Printf("%d power %d= %d",I,j,r);
J++;
}
I++;
}
// I need the output to be 1 up to 12 of powers so where is the error//