Computer Science, asked by aditichauhan69, 1 year ago

write a program to input an integer and find the sum of its digits

Answers

Answered by Amanmishra813
3

The program output is also shown below.

* C program to accept an integer & find the sum of its digits.

#include <stdio.h>

{

long num, temp, digit, sum = 0;

printf("Enter the number \n");

scanf("%ld", &num);

temp = num;

while (num > 0)

More item


Amanmishra813: Kyu
Amanmishra813: Gf hai kya
Amanmishra813: Tumhari
Amanmishra813: To kyu miss kar rahe ho
Anonymous: plz no more comments ... it is disturbing alot..plzz
Anonymous: its ok ..
Amanmishra813: Sorry jishan
Amanmishra813: Bro
Answered by Anonymous
4

CODE


import java.util.*;

class Sum_digits

{

public void main()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

int n=sc.nextInt();

int d=0;

int s=0;

while(n>0)

{

d=n%10;

s=s+d;

n=n/10;

}

System.out.println("The sum of the digits = "+s);

}

}

----------------------------------------------------

OUTPUT

Enter a number

561

The sum of the digits = 12

Hope it helps :-)

______________________________________________________________________


Amanmishra813: Hiii
Anonymous: Hi have a nice day !
Similar questions