HELP!!!

I need define a calss my_int...

a. Is it a multiple of 7,11 or 13?

b. Is the sum of the digites odd or even?

c. What is the square root value?

d.Is it a primes number?

# Class for multiple, Sume of Digits, square root value, and a prime num

## Class for multiple, Sume of Digits, square root value, and a prime num

Page 1 of 1## 3 Replies - 4061 Views - Last Post: 27 November 2008 - 10:13 PM

### #1

# Class for multiple, Sume of Digits, square root value, and a prime num

Posted 27 November 2007 - 11:38 AM

##
**Replies To:** Class for multiple, Sume of Digits, square root value, and a prime num

### #2

## Re: Class for multiple, Sume of Digits, square root value, and a prime num

Posted 27 November 2007 - 11:36 PM

Please see the forum rules. no one here is going to do your homework for you.

there have been plenty of posts on finding prime numbers so you can search the forum and find a number of examples. Same with the square root function (though C/C++ does come with a sqrt() function if you are allowed to use it).

a. Can be done using the % operator. (or, if you are into number theory there are divisibility tests that you can preform to tell if numbers are multiples of 7, 11, or 13.

b. Again these are properties of numbers and a little number theory/basic algebra goes a long way.

c. You can use the sqrt() function or you can use any number of numeric approximation techniques. Newton's method is a very popular one. There was recently a post on bisection.

d. If a number is not divisible by any prime number less than the sqrt() of the number, then that number must be prime (since all numbers can be uniquely expressed as a product of primes).

there have been plenty of posts on finding prime numbers so you can search the forum and find a number of examples. Same with the square root function (though C/C++ does come with a sqrt() function if you are allowed to use it).

a. Can be done using the % operator. (or, if you are into number theory there are divisibility tests that you can preform to tell if numbers are multiples of 7, 11, or 13.

b. Again these are properties of numbers and a little number theory/basic algebra goes a long way.

c. You can use the sqrt() function or you can use any number of numeric approximation techniques. Newton's method is a very popular one. There was recently a post on bisection.

d. If a number is not divisible by any prime number less than the sqrt() of the number, then that number must be prime (since all numbers can be uniquely expressed as a product of primes).

### #3

## Re: Class for multiple, Sume of Digits, square root value, and a prime num

Posted 27 November 2008 - 07:43 PM

Nick,

Can you help me with this program? I'm a little confused about the pointers.

Im getting error message

|51|error: invalid operands of types `int ()()' and `int' to binary `operator%'|

Any ideas

Can you help me with this program? I'm a little confused about the pointers.

#include<stdio.h> /*function prototypes*/ int number(void); int multiple(void); int even(void); int prime(void); int sum(void); void calculate (int number, int *multiple, int *even, int *prime, int *sum, int i, int *sum); int main (void) { int number, multiple, even, odd, prime, sum, i; return 0; } int number(void) /*Function to get the number from user*/ { int number; printf("Enter a Number%d", number); scanf("%d", &number); return(number); } int multiple (void) /*function to determine if the number is a multiple*/ { int multiple; if (((number%7)==0)||((number%11)==0)||((number%13)==0)) multiple=1; else multiple=0; return (multiple); } int *prime (0) /*function to return the prime number*/ { int *prime; for (i=2; i<number; i++) if ((number%i)==0) *prime=0; return (0); } int *even(void) /*function to return the even number*/ { int *even; if (number % 2 == 0) *even=1; else if (number % 2 == 1) *odd=2; return (even,odd); } int *sum (void) { int *sum; while (i!=0); { i=number%10; sum+=i; number/10; } if(*sum%2==0) *sum=1; else if (*sum%2!=0) *sum=0; return(sum); }

Im getting error message

|51|error: invalid operands of types `int ()()' and `int' to binary `operator%'|

Any ideas

### #4

## Re: Class for multiple, Sume of Digits, square root value, and a prime num

Posted 27 November 2008 - 10:13 PM

This would be better suited to its own thread, but there are several problems. You are declaring quite a few variables of type int. They are not functions in main at this point. What it looks like you want to do is initialize the variables and then pass it to your calculate prototype function.

If you wanted to call the number fucntion from main you would do:

If you wanted to call the number fucntion from main you would do:

//declare function prototypes here int main() { int num = number(); //so on and so forth }

Page 1 of 1