11332 - Summing Digits

All about problems in Volume 113. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

rajib_sust
New poster
Posts: 16
Joined: Sun Mar 02, 2008 10:34 am
Location: SUST , Sylhet, Bangladesh

11332 - Summing Digits

Post by rajib_sust »

you do not need any calculation it is just like this. this is from number theory

Code: Select all

		temp = number % 9;
		if( temp == 0 ) temp = 9;

Rajib, sust
life is beautiful like coding
mahi_seu.bd
New poster
Posts: 4
Joined: Mon Dec 06, 2010 8:25 pm
Location: Bangladesh
Contact:

Re: 11332 - Summing Digits

Post by mahi_seu.bd »

summing digit=1+(n-1)%9;
The process continues until a single-digit number is reached.
:P
It's formula knows as Digital root...
kc655039
New poster
Posts: 1
Joined: Fri Feb 18, 2005 12:49 pm

Re: 11332 - Summing Digits

Post by kc655039 »

Does anyone know how to make it take 0.000?

It still took 0.004 with the code below.

Code: Select all

#include <stdio.h>

int
main(int argc, char** argv) {
  int g;
  scanf("%d", &g);
  while (g) {
    g %= 9;
    if (g == 0) {
      g = 9;
    }
    printf("%d\n", g);
    scanf("%d", &g);
  }

  return 0;
}
Post Reply

Return to “Volume 113 (11300-11399)”