Your professor is, unfortunately, probably not smart enough to solve his own problem. The smallest possible array for this problem is size 2 (Assuming a 64-bit data type, which is the largest the standard provides for. With 32-bit integers it would need three elements, and with 128-bit integers, just 1) include #include int main(void) { int_fast64_t visited2 = { 0 }; int inputs_left = 20; do { int input, slot; int_fast64_t mask; puts("Enter an integer between 10 and 100: "); if (!scanf("%d", &input)) { puts("That's not a number!
\n"); continue; } if (input 100) { puts("Out of range! \n"); continue; } slot = (input - 10) >> 6; mask = 1.
Your professor is, unfortunately, probably not smart enough to solve his own problem. The smallest possible array for this problem is size 2 (Assuming a 64-bit data type, which is the largest the standard provides for. With 32-bit integers it would need three elements, and with 128-bit integers, just 1).
#include #include int main(void) { int_fast64_t visited2 = { 0 }; int inputs_left = 20; do { int input, slot; int_fast64_t mask; puts("Enter an integer between 10 and 100: "); if (!scanf("%d", &input)) { puts("That's not a number! \n"); continue; } if (input 100) { puts("Out of range! \n"); continue; } slot = (input - 10) >> 6; mask = 1 \n"); } else { visitedslot |= mask; printf("%d is new\n", input); } inputs_left--; } while (inputs_left); return 0; } You are welcome to use this code in your assignment, if you are able to correctly explain how it works (I hope your professor taught you how to write comments).
1. The array size would depend on the type you take. If you take a long long or a double you can manage in an array of size 2 also.
– N.R.S. Sowrabh Jul 18 at 4:41 1 I'm not smart enough to understand your solution, either, at least when it comes to storing 20 (or the first 19) numbers in an array size 3. You've assumed information not given in the question, i.e. , that the numbers input have to be integers.
If you're going to be "smart" and use bitwise operations to store more than one number in each slot in the array, I'd suggest that the smallest possible array size needed is a 1-element array (where that one element is, e.g. , an object with a field for each number). – nnnnnn Jul 18 at 4:43 +1 Nice example of bit twiddling. @nnnnnn: It seems the question was formed with integers in mind.
I'll agree that it wasn't explicitly given, but it seems like that's what was intended given by the code that was presented. – Mike Bantegui Jul 18 at 4:45 Good job, but you should modify the code to also support numbers between 10 and 19 or it doesn't satisfy the professor's requirements. – David Grayson Jul 18 at 4:47 @NRS: I edited in the possibility of using a larger integer about the same time you left your comment.
Also, bitwise operations can't be used on double. – Ben Voigt Jul 18 at 4:47.
This is what I came up with, thanks for everybody's help: #include #define MAX 20 int main() { int a MAX = { 0 }; /* user input */ int i; /* counter */ int j; /* counter */ int k = 0; /* number of integers entered */ int duplicate; /* notify of duplicates */ int value; printf( "Enter 20 numbers between 10 - 100;\n" ); /* ask user for 20 numbers */ for ( I = 0; I.
1 for trying yourself – Aditya Kumar Jul 18 at 22:02.
There are a few problems with your code: The duplicate function is inside the main function. I is declared multiple times There should not be a semicolon after your first for loop. The hold variable is not being used for anything.It is only being assigned a value.
Numi=1 - not sure what you are trying to do here, but the i=1 is setting I to 1. In your first for loop, your condition is I It should be I You will need to get 20 integers one by one and check the array each time the user enters a number. The duplicate function should probably take a second parameter, the number that you want to check for.
The if statement would check if numi equals the number you are looking for. Remember to initialize the array values and only check values that you have set. For example, when the user enters the third number, you only want to check the first 2 numbers in the array to see if it already exists.
PS: Please try to indent your code properly. Many people will not even try to help if it is not indented properly.
My C is pretty rusty, so here's a pseudo-code solution (since this is homework you should do some of it for yourself): print initial prompt; declare nums array size 20 ; // I later assume a 0-based index declare boolean found; for (i=0; I And check that all of your brackets match up.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.