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

Comments

  1. #include"stdio.h"
    main(){
    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);
    }

    ReplyDelete
  2. #include
    main()
    {
    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);
    }
    }



    ReplyDelete

Post a Comment