C语言题目12

IT小小龙 posted @ 2014年4月06日 16:21 in C with tags 交集 并集 , 643 阅读
//有两个集合, A{1,3,6,2,9}  B{1,4,6,9,10}  输出这两个集合的交集和并集到屏幕上;
#include"stdio.h"
int main()
{
  int a[5] = {1,3,6,2,9};
  int b[5] = {1,4,6,9,10};
  int i;
  int j;
  //输出交集
  printf("两个集合的交集:");
  for(i=0; i<5; i++)
    {
      for(j=0; j<5; j++)
	{
	  if(a[i] == b[j])
	    {
	      printf("%d ", a[i]);
	      break;
	    }
	}
    }
  printf("\n");
  //输出并集
  printf("两个集合的并集:");
  for(i=0; i<5; i++)
    {
      for(j=0; j<5; j++)
	{
	  if(a[i] == b[j])
	    {
	      a[i] = '#';
	    }
	}
    }
  for(i=0; i<5; i++)
    {
      if(a[i]!='#')
	{
	  printf("%d ", a[i]);
	}
    }
  for(j=0; j<5; j++)
    {
      printf("%d ", b[j]);
    }
  printf("\n");
  return 1;
}
Avatar_small
TN Board Model Paper 说:
2022年8月20日 17:47

Tamilnadu Board Model Paper 2023 Class 8 Pdf Download with Answers for Tamil Medium, English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term1 & Term2 Exams at official website. TN Board Model Paper Class 8 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter