Please help me out, need help

Reply

Join Date: Oct 2003
Posts: 4
Reputation: stehigs321 is an unknown quantity at this point 
Solved Threads: 0
stehigs321 stehigs321 is offline Offline
Newbie Poster

Please help me out, need help

 
0
  #1
Oct 9th, 2003
At least show me the logic on how to solve the math problem parts. I will put it into program if you just explain to me how to get the factors, tell the computer how many factors, find the sum and print it to screen, and find the product and print it to screen. Then i will put it all together.

Hi, im kinda new to using loops in my programming. I'm still a little rusty. could someone hep me out a little on this problem?
I sure could use some quick help from you guys. You've always been there in the past. Thanks so much.

I need a program that will prompt the user for a single positive integer greater than 1. If the user does not enter a valid integer, then the program should continue to reprompt the user for a value until a valid integer is entered. Once the integer is read in, the program will print out the following information about the integer:

1) A list of each of the positive factors of the given integer.
2) The number of factors the given integer has.
3) The sum of the factors of the integer.
4) The product of the factors of the integer.

An example output would be :

Enter a positive integer greater than one.
12

Here is a list of the positive factors of 12:
1 2 3 4 6 12

The number of positive factors of 12 is 6.
The sum of the positive factors of 12 is 28.
The product of the positive factors of 12 is 1728.

thanks so much guys.

Heres what i got so far :



int main()

{

int LoopCount = 0;
int integer;


printf("Enter a positive integer greater than one.\n";
scanf("%d", integer);


for (int j=1; j <= LoopCount; j++){
for (int integer=1; integer <=LoopCount; integer++){
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Please help me out, need help

 
0
  #2
Oct 9th, 2003
user enters NUMBER
for loop counting X from NUMBER to 1 counting backwards
if ( (NUMBER % X) == 0 ) then X is a factor
print X to the screen
continue looping


In the above algorithm, we use modular division. (e.g. number % x = number mod x) What modular division does, is it gives you the remainder when regular division is performed. Take the following example.

NUMBER = 12

x = 12
12/12=1
12%12=0
12 is a factor

x = 11
12/11=...
12%11=.....
11 is not a factor
.
.
.
x= 6
12/6=2
12%6=0
6 is a factor
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 4
Reputation: stehigs321 is an unknown quantity at this point 
Solved Threads: 0
stehigs321 stehigs321 is offline Offline
Newbie Poster

Re: Please help me out, need help

 
0
  #3
Oct 9th, 2003
so how would i put this into code? I also have to say how many factors there are, anf the sum and product of the factors.
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 4
Reputation: stehigs321 is an unknown quantity at this point 
Solved Threads: 0
stehigs321 stehigs321 is offline Offline
Newbie Poster

COMPILING ERROR??

 
0
  #4
Oct 9th, 2003
why do i get this compiling error with the following code??

numbers.c: In function `main':
numbers.c:33: `for' loop initial declaration used outside C99 mode

  1. int main() {
  2. int oneNumber =0; // hold the valid integer entered
  3. int countPositiveFactors =0; // accumulate a sum , so should be initialize to 0
  4. int sumPositiveFactors =0; // accumulate a sum , so should be initialize to 0
  5. int prodPositiveFactors = 1; // accumulate a product so should be initialize to 1
  6.  
  7. while (1)
  8. {
  9. printf("Enter an integer > 1 :");
  10. scanf("%d", &oneNumber);
  11. if (oneNumber > 1)
  12. break;
  13. else
  14. printf("Error: Number should be > 1\n");
  15. _flushall(); // to flush all streams e.g. stdin
  16.  
  17. }
  18.  
  19. printf("\n\nHere is a list of the positive factors of %d\n",oneNumber);
  20. for (int i=1;i<=oneNumber;i++)
  21. {
  22. if (oneNumber%i==0) // one factor found
  23. {
  24. countPositiveFactors++; // add 1 to count of positive factors
  25. printf("%d ",i); // print this factor
  26. sumPositiveFactors+=i; // add this factor e.g. i to the sum
  27. prodPositiveFactors*=i; // multiply this factor with the previous factors
  28.  
  29. }
  30. }
  31.  
  32. printf ("\n\nThe number of positive factors of %d is %d.\n",oneNumber, countPositiveFactors);
  33. printf ("The sum of the positive factors of %d is %d.\n",oneNumber, sumPositiveFactors);
  34. printf ("The product of the positive factors of %d is %d.\n",oneNumber, prodPositiveFactors);
  35.  
  36. return 0;
  37. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC