write a program to print all magic no between 1 to 1000 using function int sumofdigits (int d) it is used to recieve a no and return the sum of its digits of the no
Answers
Answered by
0
===================== HEYA THERE =================
------------------------- HERE US YOUR ANSWER -----------------
import java.io.*; class GFG
{
// A utility function to compute sum // of digits in a given number x
static int sumOfDigits(int x)
{
int sum = 0;
while (x != 0)
{
sum += x % 10;
x = x / 10;
}
return sum;
}
// Driver Program
public
static
void main
(String args[])
{
int n = 328;
System.out.println
("Sum of digits in numbers"
+" from 1 to " + n + " is " + sumOfDigitsFrom1ToN(n));
}
}
_________________________________
# BRAINLY2222
@ COMPUTER SCIENCE
------------------------- HERE US YOUR ANSWER -----------------
import java.io.*; class GFG
{
// A utility function to compute sum // of digits in a given number x
static int sumOfDigits(int x)
{
int sum = 0;
while (x != 0)
{
sum += x % 10;
x = x / 10;
}
return sum;
}
// Driver Program
public
static
void main
(String args[])
{
int n = 328;
System.out.println
("Sum of digits in numbers"
+" from 1 to " + n + " is " + sumOfDigitsFrom1ToN(n));
}
}
_________________________________
# BRAINLY2222
@ COMPUTER SCIENCE
Similar questions