My Math Forum  

Go Back   My Math Forum > Science Forums > Computer Science

Computer Science Computer Science Forum


Thanks Tree1Thanks
  • 1 Post By weirddave
Reply
 
LinkBack Thread Tools Display Modes
December 4th, 2016, 05:18 AM   #1
Member
 
Joined: Oct 2016
From: Slovenia, Europe

Posts: 47
Thanks: 5

Question C programming. (basics)

Please help me with my problem. I cannot find the solution.
I have two different tables, a user defines their size and their elements...
The second table always has less or equal elements than the first and all the elements of the second table are surely elements of first table too. My program prints both tables. For example:

Code:
1st table: 1 3 5 7 9
2nd table: 5 7
My question is, how to find and print elements which are in first table but they are not in the second. It should seems like this:

Code:
1st table: 1 3 5 7 9
2nd table: 5 7
in 1st table but not in the second: 1 3 9
I will be greatful if anybody helps.
srecko is offline  
 
December 5th, 2016, 11:43 PM   #2
Senior Member
 
Joined: Apr 2014
From: UK

Posts: 769
Thanks: 290

for loop through the first table, each time looping through the second table, something like this:

Code:
for (int t1loop = 0; t1loop<t1size; t1loop++)
{
  bool match = false;
  for (int t2loop = 0; t2loop<t2size; t2loop++)
  {
    if (table1[t1loop] == table2[t2loop]) then match = true;
  }
  if (match != true)
  {
    //shout about not finding the number in table 2 here. t1loop is the current number not found in table 2.
  }
}
Thanks from srecko
weirddave is offline  
Reply

  My Math Forum > Science Forums > Computer Science

Tags
basics, programming



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding python programming, specifically Object Oriented Programming mitch08 Computer Science 2 November 28th, 2015 05:51 AM
Learning algebra basics Olivia Algebra 2 December 21st, 2014 01:15 PM
books for the basics zahlenzbinden1 Math Books 2 November 30th, 2011 02:06 AM
Set Theory Basics netzweltler Applied Math 28 October 19th, 2011 10:01 AM





Copyright © 2017 My Math Forum. All rights reserved.