Computer Science, asked by 20105009, 22 days ago

Write a program to find the sum of inupt data :321 digits and out put data 6​

Answers

Answered by BrainlyProgrammer
4

Answer:

//Java Approach

import java.util.Scanner;

public class SumDigit {

⠀⠀public static void main(String[] args) {

⠀⠀⠀for(int n=new Scanner(System.in).sc.nextInt();n!=0;n/=10)

⠀⠀ sum+=n%10;

⠀ ⠀ System.out.println("The sum of the digits of "+num+" is "+sum);

⠀}

}

QBASIC

CLS

INPUT "ENTER A NUMBER"; N

S=0

WHILE N<>0

⠀⠀D=N MOD 10

⠀⠀S=S+D

N=N/10

WEND

PRINT "SUM";S

END

Similar questions