Sum of digits, count digits, prime

In my program, I must write a program that counts the number of digits

Page 1 of 1

1 Replies - 7077 Views - Last Post: 21 February 2008 - 02:24 PM Rate Topic: -----

#1 jtruman   User is offline

  • New D.I.C Head

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

Sum of digits, count digits, prime

Post icon  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   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • 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();
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1