Tech Support Forum banner
Status
Not open for further replies.
1 - 9 of 9 Posts

·
Registered
Joined
·
18 Posts
Discussion Starter · #1 ·
I was given a task where i must use a 20-element single-subscripted integer array to read in 20 numbers between 10 and 100,inclusive. And as each number is input,print it only if it is not a duplicate of a number previously input.

I already work on this for 2 days but yet i can't get a good answer...can anyone help me out with this?urgent...i am kinda new to Visual C++ and programming...i would like to thank all of u here first...your help will be greatly appreciated.
 

·
Global Moderator
Electronic Design
Joined
·
52,022 Posts
Well, it won't win any style contests, but I just wacked it out in about 10 minutes. :smile:

Code:
#include <stdio.h>
#include <stdlib.h>

#define FALSE 0
#define TRUE !FALSE

void main (void)
{
   int numbers[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
   int i,j;
   int temp;
   int match;

   for (i = 0;i < 20;i++)
   {
      temp = 0;

      while ((temp < 10) || (temp > 100))
      {
         printf("Enter a number (%i to go, 999 to quit: ",20-i);
         scanf("%i", &temp);
         if (temp > 998)
            exit(0);
      }

      match = FALSE;

      for (j=0;j < 20;j++)
      {
         if ((temp == numbers[j]) && (numbers[j] != 0))
         {
            match = TRUE;
            break;
         }

      }


      if (!match)
      {
         printf("A new number! : %i\n", temp);
         numbers[i] = temp;
      }

   }

}
 

·
Registered
Joined
·
18 Posts
Discussion Starter · #4 ·
well john...although the output is not like what i expected...i really appreciate your help...u are great....thanks! I can't really understand the program coz maybe i am too noob...lolz! Anyway...hopefully i can learn more next time from here and from u all guys!
 

·
Registered
Joined
·
18 Posts
Discussion Starter · #7 ·
dun misunderstood man...i really appreciate your help...thanks! Maybe my english is not good and u understand the question more than me right???lolz!
Hmm...i will take your suggestion mark...thanks to u too!
 

·
Global Moderator
Electronic Design
Joined
·
52,022 Posts
Well, if you're going to be a professional programmer, my suggestion would be to stick with C/C++, it's the language of choice for major projects.
 

·
Registered
Joined
·
18 Posts
Discussion Starter · #9 ·
thanks to u john...i will listen to your words and try to stick with C or C++. But i heard java programmers nowadays are highly demanded...isn't it?

Btw...i have another headache task again john...can u help me out with it?i posted it on a new thread....thanks a lot if u can.
 
1 - 9 of 9 Posts
Status
Not open for further replies.
Top