class Sum_Of_Digits
{
public static void printSumandnoofdigits(int n)
{
int temp = n;
int count = 0;
int sum = 0;
while ( n > 0 )
{
sum = sum + n % 10;
n = n / 10;
count ++;
}
System.out.println("The number is..." + temp );
System.out.println("The sum of digits is..." + sum);
System.out.println("The number of digits is..." + count);
}
}
Yes, do write, or if you're too lazy to your homework, use google.
Add the digits together. The sum of the digits of 23 is 5.
Yes, do write. That's what you always have to do when you have got a homework-program.
Write down the numbers from 1000 to 9999.
To assess the number of significant digits in a number, you first have to find the greatest non-zero digit. In this case it is the first five which represent 500. The next step is to simply count how many digits there are after this number. In this case, there are 4 more digits. Thus the number 500.95 has been given to 5 significant digits.
no thanks
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
#include <stdio.h> int main(int argc, char **argv) { if (argc<1) { printf("Usage: %s number\n",argv[0]); return -1; } int digits=1, i=atoi(argv[1]); while (i/=10) ++digits; printf("%d\n",digits); }
5
There are many shell programs that will find the sum of the square of individual digits of a number. A small example is: SD=3n=2, sum=2, and SD=2.
k
You can use the Math.sqrt() method.
Shell problems are programs that can be run to find out information about numbers. The problem can help find an even or odd number, or what the sum of a cube is.
Yes, do write, or if you're too lazy to your homework, use google.
Write your own prime number program and find out.
Add the digits together. The sum of the digits of 23 is 5.
45