Can You Write A Program To Compute Sum Of Digits Of A Given Number?

4

4 Answers

Anonymous Profile
Anonymous answered
Void main()

    {
    int I,sum=0,n;
    System.out.print("nEnter a number:");
    int n =input.nextInt();
    while(n!=0)

  {
  I=n%10;
  n=n/10;
  sum=sum+I;
    }

    System.out.println("nThe sum=",sum);
  }
Anonymous Profile
Anonymous answered
Write a form application to print sum and product of digits of given number in vb.net
Anonymous Profile
Anonymous answered
void main()

    {
    int I,sum=0,n;
   
System.out.print("nEnter a number:");
    int n =input.nextInt();
    while(n!=0)

        {
        I=n%10;
        n=n/10;
        sum=sum+I;
    }

   
System.out.println("nThe sum=",sum);
  }

Have fun :)
Anonymous Profile
Anonymous answered
Void main()

    {
    int I,sum=0,n;
    System.out.print("nEnter a number:");
    int n =input.nextInt();
    while(n!=0)

  {
  I=n%10;
  n=n/10;
  sum=sum+I;
    }

    System.out.println("nThe sum=",sum);
  }

Answer Question

Anonymous