943,682 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 977
  • C++ RSS
May 13th, 2008
0

Need Help Immediatedly Please

Expand Post »
Please help me in doing this problem in C++ without filing

______________________________________________________________________
C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #define min(a,b)((a)<(b)?(a):(b))
  5. int a[6000];
  6. main()
  7. {
  8. file*input=fopen("number.in","r");
  9. int n,p2,p3,p5,p7;
  10. a[1]=n=p2=p3=p5=p7=1;
  11. while (a[n]<2000000000)
  12. {
  13. a[1+n]=min4(2*a[p2],3*a[p3],5*a[p5],7*a[p7]);
  14. if (a[n]==2*a[p2]) p++;
  15. if (a[n]==3*a[p3]) p++;
  16. if (a[n]==5*a[p5]) p++;
  17. if (a[n]==7*a[p7]) p++;
  18. }
  19. {
  20. fscanf(input,"%d",&n);
  21. if (n==0) break;
  22. printf("the%d",n);
  23. if (n%10==1&& n/10% 10!=1)
  24. printf("st");
  25. else if(n%10==2&& n/10% 10!=1)
  26. printf("nd");
  27. else
  28. if(n%10==3&& n/10% 10!==1)
  29. printf("rd");
  30. else
  31. printf("th")
  32. printf("humble number is %d\n",a[n]);
  33. }
  34. fclose(input);
  35. return 0;
  36. }
Last edited by Ancient Dragon; May 13th, 2008 at 9:39 am. Reason: add code tags
Similar Threads
Reputation Points: 40
Solved Threads: 7
Junior Poster
architact is offline Offline
114 posts
since Apr 2008
May 13th, 2008
0

Re: Need Help Immediatedly Please

What is it that u need help with, what the project is doing, where are u stucked with the project.....sure everybody would like to know that hey
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
May 13th, 2008
0

Re: Need Help Immediatedly Please

sorry i forgot to mention that the project is that user enters a number and the programme return a humble number
e.g
user enters 3;
the program should return the 3rd humble number
Reputation Points: 40
Solved Threads: 7
Junior Poster
architact is offline Offline
114 posts
since Apr 2008
May 13th, 2008
0

Re: Need Help Immediatedly Please

A few things come to my attention:

C++ Syntax (Toggle Plain Text)
  1. int n,p2,p3,p5,p7;
  2. a[1]=n=p2=p3=p5=p7=1;
That's awful, what are you doing here?
C++ Syntax (Toggle Plain Text)
  1. while (a[n]<2000000000)
  2. {
You never increase n, so it will always write in the same element,
Besides: You declared 'a' as an array of 6000 ints, so there's no room for 2000000000 numbers.
C++ Syntax (Toggle Plain Text)
  1. {
  2. fscanf(input,"%d",&n);
What's the bracket for?

And that's just the tip of the iceberg, but before I continue:

Use code tags and indent your code. Then as a clear question about it.

[edit] And about main()
Last edited by Nick Evan; May 13th, 2008 at 8:38 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
May 13th, 2008
0

Re: Need Help Immediatedly Please

please forget the code what i want to do is that user enters a number from keyboard the program in ouput displays the humble number
Example:
input = 5842
output = the 5842nd humble number is 2000000000
Reputation Points: 40
Solved Threads: 7
Junior Poster
architact is offline Offline
114 posts
since Apr 2008
May 13th, 2008
0

Re: Need Help Immediatedly Please

The first thing that you have to do is find all the prime numbers except 2, 3, 5 and 7 till the number which is input. Then check if the prime numbers is a factor of the number. If it is not its humble.
Reputation Points: 10
Solved Threads: 1
Light Poster
DigitalPackrat is offline Offline
33 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: linked list insertion problem
Next Thread in C++ Forum Timeline: Need advice on shortest path algorithms





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC