Digit split and sum
Write a program to split all the digit from a given integer input and make sum of all digits.
Sample Input: 13245
Sample Output:
The digits are:
1
3
2
4
5
Sum: 6
Sample Input: 13245
Sample Output:
The digits are:
1
3
2
4
5
Sum: 6
#include"stdio.h"
ReplyDeletemain(){
int a=1564;int sum=0,b,i,l;
for(i=0;i<5;i++){
while(a>0){
b=a%10;
a=a/10;
printf("%i\n",l);
//printf("\n\n");
sum+=b;
}
}
printf("\nThe sum of above numbers is : %d",sum);
}
#include
ReplyDeletemain()
{
int a=721;
int sum=0,b,j,x;
for(j=0;j<5;j++)
{
while(a>0)
{
b=a%5;
a=a/5;
printf("%j\n",x);
printf("\n\n");
sum+=b;
}
printf("\n the sum of above num is:%d",sum);
}
}