### can someone assist me

closed account (oNRiz8AR)
can someone help me with the following:

for all of the following use pointers (if necessary) and arrays:
(a) print 30 prime numbers greater than 1001
(b) print 30 random numbers greater than 1 and less than 1000 and print the largest integer of this list
(c) print 30 numbers divisible by 8 and greater than 100
(d) print 30 random numbers grater than 10 and less than 100 and print the smallest number

For the first, make an array of the prime numbers between 1 and 1001 (if need-be, I can provide such). Then have a for loop that has a number starting at 1002, which checks whether the number is prime or not by dividing it by every term in the first array. If the number is prime (remainder of each division is not zero), display it, and move on.
What have you tried to do so far, yourself? Where's your code?
Anyway. To get random numbers you can use the std::rand() function.

Disclaimer: code not tested.

 ``1234567891011121314151617181920`` ``````#include #include #include #include int give_rand(int min, int max) { int range = max - min; return std::rand() % range + min; } int main() { // seed the random number generator // (only needs to be done once) std::srand(std::time(NULL)); std::clog << give_rand(2, 999) << '\n'; }``````
closed account (oNRiz8AR)
If you can provide me with code great. If you do so it will help me finish off all the others!!!
closed account (oNRiz8AR)
5 have used codes from others posted on different websites and on the book that I have for C++.
closed account (oNRiz8AR)
 ``1234567891011121314151617181920212223242526`` `````` #include #include #include #include int give_rand(int min, int max) { int range = max - min; return std::rand() % range + min; } int main() { int k; for(k = 0; k < 30; k++) {std::srand(std::time(NULL)); std::clog << give_rand(2, 999) << '\n'; } } ``````

I used this code and it prints the same number 30 times, the numbers need to be distinct, not all repetitive as this is the case
I see you ignored my std::srand() comments.

 ``123456789101112131415161718192021222324252627282930`` ``````#include #include #include #include int give_rand(int min, int max) { int range = max - min; return std::rand() % range + min; } int main() { // seed the random number generator // (only needs to be done once) std::srand(std::time(NULL)); for (int k=0; k < 30; ++k) std::clog << give_rand(2, 999) << '\n'; }`````` ```832 281 991 429 761 264 82 618 315 898 103 471 326 110 994 813 783 513 293 848 415 812 106 817 58 348 76 995 641 145```
closed account (oNRiz8AR)
 `` `` ``cout << "Thank you so much!! " << endl;``
closed account (oNRiz8AR)
Do you know how to print the largest number of this code:

 ``1234567891011121314151617181920212223`` ``````#include #include #include #include int give_rand(int min, int max) { int range = max - min; return std::rand() % range + min; } int main() { // seed the random number generator // (only needs to be done once) std::srand(std::time(NULL)); for (int k=0; k < 30; ++k) std::clog << give_rand(2, 999) << '\n'; } ``````
Here is the complete code for you>
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` ``````//Codded by_Lutu Putu_(From Independent university, Bangladesh) #include #include #include using namespace std; int main() { srand(time(0)); int a[30], i, j, count=0, countt=0, h=0, l; cout<<"(a) 30 prime numbers greater than 1001 is:\n"; for(i=1002; ; i++){ for(j=2; ; j++){ if(i%j==0) break; } if(i==j){ if(count<30){ count++; cout<a[i]) l=a[i]; } cout<<"\b; and,\nSmallest integer in the list is: "<
]
@ Sam99: You really need to stop joining threads where people are trying to help the OP actually learn something and ruin it for them by posting a full solution. Doing their homework for them is not going to help, only hurt. Are you going to take their tests for them too? If not, they're going to fail them since they didn't learn how write code for themselves.
@ cnoeval: I disagree with your post.

The main reason why I personally didn't post a full solution was because I am lazy.

I believe that someone who wants to learn will learn just as easily (if not easier) by studying a full solution. Otherwise, if they don't really care about learning -- we might as well give them a full solution anyway, because it doesn't matter.
@cnoeval
It doesnt mean that, I m doing their homework... If u mean that, they need just their homework help instead of of learning anything from the solution and I m doing their homework, then that is really your thought; not mine and others like me.
If you hate to do others homework, then you avoid to do that...
My job is to help them; In addition- Its my practice, not others homework...
Good luck...
 I believe that someone who wants to learn will learn just as easily (if not easier) by studying a full solution.

All teachers need to do is supply a fully working program for their students to dissect and they're all good?

Do you learn to apply math skills by staring at solutions?

If the goal is to learn to write code, a critical component of that education is writing code. Besides, the code provided is rife with bad habits and an inconsistent indentation style that it would be better for a newbie not to be exposed to.

Sam99 wrote:
Its my practice, not others homework...

Last edited on
 All teachers need to do is supply a fully working program for their students to dissect and they're all good?

There's a misunderstanding. I meant what I wrote in the context of giving full vs giving partial solutions in threads such as this one. At school things are different.

 Do you learn to apply math skills by staring at solutions?

Do you learn programming by studying other people's code?

 If the goal is to learn to write code, a critical component of that education is writing code.

Edit: achieved by... studying other people's code perhaps?

Edit 2: wait, I'm confused. The point is, monkeys and keyboards.
Last edited on
If you think looking at well written code will teach you some overall concepts I agree. If you think you will be able to reproduce what an expert created just by looking at his code you're soon to be disappointed. That's like saying you can watch a great artist paint or play an instrument for long enough and then sit down and do it yourself. Coding is a logical AND creative process. Unless you exercise your creative skills you'll never be a great programmer. Practice DOES count. You have to build on what has already become second nature to you.

Want proof? Simple. laden20, look at Sams code all you want. Now close it and open a blank editing window and write your own version...

Catfish, if they don't want to learn, you're right that there's no help for them. So WHY are you helping them cheat their way through school? I'm too old to care but you may end up with someone like that as a co-worker. Good luck with that! 8^}
@cire

 Do you learn to apply math skills by staring at solutions?

Oddly enough, in most cases, that's exactly what i do with math...

I do however understand the point. Giving out the answer doesn't always help people learn. I'm still learning, and I can say that if someone just pops off an answer right away it sucks. I like being shown rough examples that make me go out and understand how it all works. I will of course do the same thing if someone posts the code because I still want to understand it since I know I wont get any freebies in the real world. If someone posts stuff for me after a few days of help and I'm still not grasping it, then that usually helps a lot in getting me to see what it is I'm missing. Chances are though, I won't use what they have given me though, since my teacher isn't stupid, and he does look around places like this to see if people are cheating. They have actually caught people doing just that, and dropped them from the class, so it's a double edged sword. I can get the code, which will help me understand better, but it's also almost certain to force me to find another way to do it, which teaches me even more.
 There's a misunderstanding. I meant what I wrote in the context of giving full vs giving partial solutions in threads such as this one. At school things are different.

This is homework. Practice given to students to help engender problem solving skills and generate experience programming solutions to specific problems.

Supplying a full solution to homework lessens the likelihood that either goal is achieved. This is part of school for many people here. Those people who are likely to attempt it anyway? They probably googled first and found an already existing set of solutions and explanations. At the very least, they've come up with a little code of their own, which one can't say for the OP.
Topic archived. No new replies allowed.