add all the digits in the number together and you will have the sum of the digits in the number.
12345 = 15
46854 = 27
2007-02-14 19:54:10
·
answer #1
·
answered by clever investor 3
·
0⤊
1⤋
In VB the way I would do it is:
Say the digit is 12345678 and you have this under a name MyDigit.
SumDigit=0
if len(MyDigit)>0 then
For s=1 to len(MyDigit)
SumDigit=SumDigit + val(mid(MyDigit,s,1))
next s
End if
This will count up any value you put into "MyDigit" and the answer will be stored in "SumDigit". The syntax may be a bit different in C.
Good luck.
2007-02-15 04:09:42
·
answer #2
·
answered by PolarBear 1
·
0⤊
0⤋
Well, i guess you need a program to do that, as you didnt specify a language you can just follow this algorithm
Get (Number)
While (NextNumber exists) //while you can get a next number
{
Number = NextNumber
Sum = Sum + Number
}
Display Sum
2007-02-15 04:03:02
·
answer #3
·
answered by mrcpp81 1
·
0⤊
0⤋
main()
{
int num = 5678;//number for which sum to find out
int sum =0;
for(;num>0;sum += num%10,num /=10);
printf("sum is %d\n",sum);
}
Sorry for the messy style, but currently I am reading Kerningham, Ritchie.
2007-02-16 03:15:20
·
answer #4
·
answered by manoj Ransing 3
·
0⤊
0⤋
/*In TURBO C this might works.*/
/*header file section*/
#include
#include
void main()
{
int n; /*this refers to initialisation of input number*/
static int q,sum,n1; /*keeps n1,sum,q to 0 to avoid warnings*/
clrscr();
printf("enter a number");
scanf("%d",&n);
n1=n;
while(n!=0)
{
q=n%10; /*this takes the last digit of the given number*/
sum=sum+q; /* this adds the the current digit to thesum;
n=n/10;
}
printf("the sum of digits of the given no %d is %d",n1,sum);
getch();
}
2007-02-15 04:52:49
·
answer #5
·
answered by PRABHAKAR G 1
·
0⤊
0⤋
main()
{
int num = 12345678; // or whatever you want
int sum = 0;
while (num > 10) {
sum+=num%10;
num/=10;
}
sum+=num;
}
haven't tested it but I believe this will work
2007-02-15 12:08:51
·
answer #6
·
answered by bytekhan 2
·
0⤊
0⤋
well, you can simply add up the numbers. I'm not sure if you're looking for a simpler way to add up more complex numbers.
2007-02-15 03:57:54
·
answer #7
·
answered by Anonymous
·
0⤊
1⤋
#include
#include
//i hope this will help u
void main()
{
long int num,n,sum=0;clrscr();
printf("\nEnter a number:");scanf("%ld",&num);
for(n=num;n>0;n/=10)
sum+=n%10;
printf("\nSum of Digits of %ld :%ld",num,sum);
}
2007-02-15 04:11:20
·
answer #8
·
answered by KillingJoke 3
·
0⤊
0⤋
Program it on Computer and get the answer.
2007-02-15 04:08:43
·
answer #9
·
answered by khuranapvp 3
·
0⤊
1⤋
Add them up.
2007-02-15 03:54:54
·
answer #10
·
answered by Gnomon 6
·
0⤊
1⤋