Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Closed Thread
 
Thread Tools
Old 11-20-05, 07:31 PM   #1
Dr_s99
geForce 4 Ti 4600
 
Dr_s99's Avatar
 
Join Date: Sep 2003
Location: Canada
Posts: 339
Default C programming

hello,
:P
I need hellp with this question!
its a easy question except my brain has stopped working after the math mid-term!

The Question is:
Use a single-subscripted array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.

Thank you,
__________________
System info(s):
-----
Gaming/Work System :
ASUS G1
RAM: 2.0Gb
Hard drive: 160 Gb
VIDEO CARD: NVIDIA 7700Go 512Mb
OS: Windows Vista Home Pre.
----------------------------
Server/Work system:
CPU: AMD Athlon XP 2400+
RAM: 1.0Gb
Hard drive: 30 IDE,120 IDE
VIDEO CARD: Nvidia Geforce 4 Ti 4600
OS: OpenSuse 10.2, Windows 2003
Dr_s99 is offline  
Old 11-20-05, 10:29 PM   #2
supra
2JZ powered
 
supra's Avatar
 
Join Date: Dec 2004
Location: Aus
Posts: 1,321
Send a message via MSN to supra
Default Re: C programming

i havent programmed C in a long long time now but maybe something like this?


int num[19];
int x;

void main()
{
for (x = 0; x < 20; x++)
{
printf("please enter value for %d : ", i);
scanf("%d", &num[x]);

if (num[x] < 10 || num[x] > 100)
{
printf("value must be between 10-100");
printf("please enter value for %d : ", i);
scanf("%d", &num[x]);
}
else
{
//for loop to go through num array to check for duplicates
//soz, too lazy to code the rest lol
}

}
}
__________________
supra is offline  
Old 11-20-05, 11:09 PM   #3
Zelda_fan
Registered User
 
Join Date: Aug 2004
Posts: 10,299
Default Re: C programming

so basically you are asking us to do your homework for you. lol
Zelda_fan is offline  
Old 11-21-05, 03:54 AM   #4
Greg
Registered User
 
Join Date: Aug 2002
Location: Australia
Posts: 1,177
Default Re: C programming

Quote:
Originally Posted by Zelda_fan
so basically you are asking us to do your homework for you. lol
Who's suggesting to give the right answer Some forums actually have a homework policy.
Greg is offline  
Old 11-21-05, 07:42 AM   #5
Dr_s99
geForce 4 Ti 4600
 
Dr_s99's Avatar
 
Join Date: Sep 2003
Location: Canada
Posts: 339
Default Re: C programming

lol well not really :P or maybe i am :S
i can't see how the loop is for checking to see if a number is duplicate or not!
__________________
System info(s):
-----
Gaming/Work System :
ASUS G1
RAM: 2.0Gb
Hard drive: 160 Gb
VIDEO CARD: NVIDIA 7700Go 512Mb
OS: Windows Vista Home Pre.
----------------------------
Server/Work system:
CPU: AMD Athlon XP 2400+
RAM: 1.0Gb
Hard drive: 30 IDE,120 IDE
VIDEO CARD: Nvidia Geforce 4 Ti 4600
OS: OpenSuse 10.2, Windows 2003
Dr_s99 is offline  
Old 11-21-05, 12:31 PM   #6
Subtestube
Anisymbolic
 
Subtestube's Avatar
 
Join Date: Aug 2004
Location: Wellington, New Zealand
Posts: 1,365
Default Re: C programming

My assumption is that supra just means to do a complete check of everything in the array for each number that's read in. All you do in that for loop is check the current input against all the others already in... If you find a duplicate, just set a flag saying 'don't print', and then when you get to the end of the main for loop, print only when the don't print boolean is false, and then re-set it.

Also, bear in mind that Supra's solution uses a size 19 array. That's fine, but you must not try to read the 20th number into the array if you're going to do that, as you'll be out of bounds. You'll need to keep it in an integer (which isn't saving any space in any case). Although numbering starts at 0, a size 19 array will start at 0 and finish at 18 - you won't be able to store the 20th number in it.

EDIT: Also, you shouldn't come here trying to get people to do homework for you - it's not a good look ;|. I'll give advice on how to code a solution, but I won't give you code. (If this were a genuine code problem like "I'm making a graphics thing, how do I get a window in the screen using the GLUT, I'd be much more willing to help).
__________________
Dr Possible: Core 2 Duo E6400 on Gigabyte GA-965P-DS4. Galaxy GeForce 7600GT. 2GB Corsair XMS 2 DDR2-6400 RAM (CL5). ATi Theatre 550 Pro. Windows XP MCE. All stored in Piano black Antec Sonata II, with a broken door.

Mobile: ASUS M2400N, Pentium M 1.5 GHz. 512 MB DDR RAM. Intel EXTREME graphics. Windows XP SP 2 / Ubuntu 5.10.

Ridiculous DOES not have an 'e' in it. It comes from "ridicule" and has less than nothing to do with the colour red.
Subtestube is offline  
Old 11-21-05, 01:19 PM   #7
wnd
Nerd, Geek, Freak
 
wnd's Avatar
 
Join Date: Sep 2005
Location: Finland
Posts: 703
Default Re: C programming

If you really want to pack the stuff in an array as small as possible concider not wasting one bit per number (as numbers [10, 100] = [0, 90] can be presented with seven bits). This way it is trivial to spend only 17 octets (or 8-bit bytes) for storing those 19 numbers you have to.

IMO your assignment would have made more sense (while still being trivial) if the input would've been large (like 10^9 numbers) and you would be to optimize performance instead.
__________________
web | cat

Christianity, noun: The belief that a cosmic Jewish Zombie who was his own father can make you live forever if you symbolically eat his flesh and telepathically tell him you accept him as your master, so he can remove an evil force from your soul that is present in humanity because a rib-woman was convinced by a talking snake to eat from a magical tree. [mad.frog]
wnd is offline  
Old 11-22-05, 11:27 AM   #8
seeker010
Registered User
 
Join Date: Sep 2003
Posts: 112
Default Re: C programming

take only what you need
malloc()...
free()
seeker010 is offline  

Old 11-22-05, 12:14 PM   #9
Subtestube
Anisymbolic
 
Subtestube's Avatar
 
Join Date: Aug 2004
Location: Wellington, New Zealand
Posts: 1,365
Default Re: C programming

Hah! True - nice work wnd. That's a clever way to use no more space than required, though I doubt that that's what's required of them.
__________________
Dr Possible: Core 2 Duo E6400 on Gigabyte GA-965P-DS4. Galaxy GeForce 7600GT. 2GB Corsair XMS 2 DDR2-6400 RAM (CL5). ATi Theatre 550 Pro. Windows XP MCE. All stored in Piano black Antec Sonata II, with a broken door.

Mobile: ASUS M2400N, Pentium M 1.5 GHz. 512 MB DDR RAM. Intel EXTREME graphics. Windows XP SP 2 / Ubuntu 5.10.

Ridiculous DOES not have an 'e' in it. It comes from "ridicule" and has less than nothing to do with the colour red.
Subtestube is offline  
Old 11-22-05, 02:49 PM   #10
Dr_s99
geForce 4 Ti 4600
 
Dr_s99's Avatar
 
Join Date: Sep 2003
Location: Canada
Posts: 339
Default Re: C programming

nvm i finnished it myself!!
thank you!
__________________
System info(s):
-----
Gaming/Work System :
ASUS G1
RAM: 2.0Gb
Hard drive: 160 Gb
VIDEO CARD: NVIDIA 7700Go 512Mb
OS: Windows Vista Home Pre.
----------------------------
Server/Work system:
CPU: AMD Athlon XP 2400+
RAM: 1.0Gb
Hard drive: 30 IDE,120 IDE
VIDEO CARD: Nvidia Geforce 4 Ti 4600
OS: OpenSuse 10.2, Windows 2003
Dr_s99 is offline  
Old 07-18-11, 02:23 AM   #11
PETAPAL
Registered User
 
Join Date: Jul 2011
Posts: 1
Default Re: C programming

#include <stdio.h>
#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 <= MAX - 1; i++ ){

duplicate = 0;
scanf( "%d", &value);

/* decide if integer is duplicate */
for ( j = 0; j < k; j++ ) {

/* notify and stop loop if duplicate */
if ( value == a[ j ] ) {
duplicate = 1;
break;
{ /* end if */



/* enter number into array if it's not a duplicate */
if ( !duplicate )

a[ k++ ] = value;

} /* end if */
PETAPAL is offline  
Old 07-18-11, 01:26 PM   #12
ViN86
 
Join Date: Mar 2004
Posts: 15,486
Default Re: C programming

I doubt the OP still has this problem or even visits the forums anymore, but I have moved the thread to the proper section.
ViN86 is offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Video: New Accelerations for Parallel Programming News Archived News Items 0 06-25-12 07:20 AM
Google Blockly: New Visual Programming Language News Archived News Items 0 06-13-12 06:00 AM
Video: Programming Heterogeneous Many-cores Using Directives News Archived News Items 0 05-23-12 08:00 AM
nCore Schedules Popular Multicore Programming Course for Houston News Archived News Items 0 05-14-12 05:00 PM
Slidecast: Scalable HPC ' New Accelerations for Parallel Programming Languages over News Archived News Items 0 05-08-12 07:10 AM

All times are GMT -5. The time now is 12:18 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2014, nV News.