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.
#include <cstddef>
#include <cstdlib>
#include <ctime>
#include <iostream>
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';
}
#include <cstddef>
#include <cstdlib>
#include <ctime>
#include <iostream>
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';
}
#include <cstddef>
#include <cstdlib>
#include <ctime>
#include <iostream>
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';
}
@ 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.
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.
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.
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^}
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.