473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

creating an array with different array value

hi im new here and still a beginner in C. i need an answer to this problem and hopefully u can help me in this.

we have this challenge asked by an instructor to create an array program that will input integers and if you input an integer it must have no same input value with other array index and will not accept it. therefore it is unique. example if i input 1 in array[0], array[0] will only have the integer 1 on it and no other.

this is all what ive come up with

Expand|Select|Wrap|Line Numbers
  1. void unique (int la[], int n)
  2. {
  3.  int i;
  4.  for(i=0;i<n;i++)
  5.  {
  6.   scanf("%d", &la[i]);
  7.  }
  8. }
cant seem to solve the unique part T_T. hope u can help me solve it ^_^
Feb 13 '08 #1
4 1635
Ganon11
3,652 Expert 2GB
So at any point in time, if you are inputting number N to array element i, then array[i-1], array[i-2], array[i-3],...,array[1], and array[0] cannot hold the value N. If none of them held N, you're good to go. If you found N somewhere else, you need a new N value.
Feb 13 '08 #2
yup... it will promt the user to enter another value coz the N value has been entered. the thing is i dont know how to program this kind of problem T_T ..

Hope u can help me
Feb 14 '08 #3
Ganon11
3,652 Expert 2GB
Take a look at my post again - there's a pretty major hint on how to go about solving this problem. I'll try and repeat:

Let's say you'll use a function, named isRepeat, that will see if a value passed to it is found in an array, also passed as an argument. If the value is found, it returns true (1) - if the value is not found, it will return false (0). So we have a function like this:

Expand|Select|Wrap|Line Numbers
  1. int isRepeat(int array[], int array_size, int value)
Now, array_size doesn't have to be the actual maximum size of the array. It could be the number of elements read in. For instance, when you are reading in the first element (the array is empty), then when you call check, you might say:

Expand|Select|Wrap|Line Numbers
  1. isRepeat(array, 0, val);
You know for certain that the value is not a repeat, because there are no other elements in the array that could possibly hold that value.

Now, during any call of isRepeat, you know that you will return true (1) if you find val in any point in the array before array_size - that is, if array[0], array[1], array[2],..., array[array_size-2], or array[array_size-1] is value. If you finish checking all of these indexes and didn't find value, then there is no repeat, and you return false 0.

This is way more than enough for you to write the code yourself. All you need to do is think of how you can write isRepeat - using the hints I've provided - and how you will use isRepeat when reading values into your array.
Feb 14 '08 #4
ok thx for the help....
Feb 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
7
by: Micheal Artindale | last post by:
I am looking at creating list of letter combinations. letters a-h 6 letters per combination letter can repeat its self in the combination, but not next to its self and, a series of letter can...
9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
2
by: Dino | last post by:
I need to create a public multi-dim array that can hold a mixture of string and int values. I will need to search this array for a value and return a value from a subscript. This array will...
4
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
15
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array...
11
by: Matthew Wells | last post by:
Hello. I have figured out how to create an instance of an object only knowing the type by string. string sName = "MyClassName"; Type t = Type.GetType(sName); Object objNew =...
37
by: Richard Heathfield | last post by:
candide said: They aren't. An array is an array. An address is a pointer value. These are not the same thing. If you mean that &array and &array are the same, they aren't. They have different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.