# Sum of digits, count digits, prime

Page 1 of 1

## 1 Replies - 7077 Views - Last Post: 21 February 2008 - 02:24 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=43997&amp;s=5ffe34585de35b47705c0220480e372c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jtruman

Reputation: 0
• Posts: 1
• Joined: 21-February 08

# Sum of digits, count digits, prime

Posted 21 February 2008 - 02:01 PM

```#include<stdio.h>
#include<stdlib.h>

void GetString(char str[]);	 //1
bool isNumber(char str[]);	  //2
int sumOfDivisors(char str[]);  //3
bool isDigit(char c);		   //4
int countDigits(int n);		 //5
int sumDigits(int n);		   //6
void Display();				 //7
int stringToInteger(char str[]);//8
bool isPrime(int n);			//9

int main(void)
{
/*Get string that represents a number. Check to see if it is valid or not.*/
int m;
char str[20];
getNumber(str);
GetString(str);
printf("The number is %s\n",str);
if(isNumber(str))
{
printf("valid\n");
else
printf("invalid\n");
m=sumOfDivisors(str);
print("Sum of divisors is %d\n",m);
return 0;
}

void GetString(char str[])	  //1
{
printf("Enter number: ");
scanf("%s", str);
return;
}

bool isNumber(char str[])	   //2
{
int i;
i=0;
while(str[i] != '\0')

if('0'<=str[i]&&str[i]<='9')
i=i+1;
else
return(false);

return(true);

}

int sumOfDivisors(char str[])   //3
{
int m,n, sum;
m = atoi(str);
n=1;
sum = 0;
while (n<=m)
{
if (m%n==0)
sum=sum+ n;
n = n + 1;
return sum;
}
}

bool isDigit(char c)			//4
{
}

int countDigits(int n)		  //5
{
int m;
while (0<=m<=100)

}

int sumDigits(int n)			//6
{
}

void Display()				  //7
{
}

```

Is This A Good Question/Topic? 0

## Replies To: Sum of digits, count digits, prime

### #2 letthecolorsrumble

• Student of The Sun

Reputation: 27
• Posts: 555
• Joined: 07-November 07

## Re: Sum of digits, count digits, prime

Posted 21 February 2008 - 02:24 PM

Using the modulo operator ( % ) with 10 you can count the number of digits in a number. Also please explain in detail the places where you face problems, it will help us help you better.

P.S. : Close your if statement bracket in main();