发布网友 发布时间:2024-10-04 03:52
共2个回答
热心网友 时间:2024-10-12 03:09
#include <stdio.h>热心网友 时间:2024-10-12 03:14
#include<iostream>using namespace std;int main(){ int a,b; int c,d; cout<<"请输入第一个闭区间的a,b"<<endl; cin>>a>>b; cout<<"请输入第二个闭区间的c,d"<<endl; cin>>c>>d; if(a>b||c>d) {cout<<"输入的区间不合法"<<endl;} else { if(d<a) { cout<<"交集为:空集"<<endl; cout<<"并集为:"<<"["<<c<<","<<d<<"]"<<","<<"["<<a<<","<<b<<"]"<<endl; cout<<"差集为:"<<"["<<a<<","<<b<<"]"<<endl; } else if(c>b) { cout<<"交集为:空集"<<endl; cout<<"并集为:"<<"["<<a<<","<<b<<"]"<<","<<"["<<c<<","<<d<<"]"<<endl; cout<<"差集为:"<<"["<<a<<","<<b<<"]"<<endl; } else if(c<a) { int min,max; if(d>b) min=b,max=d;else min=d,max=b; cout<<"交集为:"<<"["<<a<<","<<min<<"]"<<endl; cout<<"并集为:"<<"["<<c<<","<<max<<"]"<<endl; if(d>=b) cout<<"差集为:空集"<<endl; else cout<<"差集为:"<<"["<<d-1<<","<<b<<"]"<<endl; } else { int min,max; if(d>b) min=b,max=d;else min=d,max=b; cout<<"交集为:"<<"["<<c<<","<<min<<"]"<<endl; cout<<"并集为:"<<"["<<a<<","<<max<<"]"<<endl; if(c<=a) cout<<"差集为:空集"<<endl; else { cout<<"差集为:"<<"["<<a<<","<<c-1<<"]"; if(d<b) { cout<<","<<"["<<d-1<<","<<b<<"]"; } cout<<endl; } } } return 0;} 望采纳,谢谢热心网友 时间:2024-10-12 03:14
#include <stdio.h>热心网友 时间:2024-10-12 03:12
#include<iostream>using namespace std;int main(){ int a,b; int c,d; cout<<"请输入第一个闭区间的a,b"<<endl; cin>>a>>b; cout<<"请输入第二个闭区间的c,d"<<endl; cin>>c>>d; if(a>b||c>d) {cout<<"输入的区间不合法"<<endl;} else { if(d<a) { cout<<"交集为:空集"<<endl; cout<<"并集为:"<<"["<<c<<","<<d<<"]"<<","<<"["<<a<<","<<b<<"]"<<endl; cout<<"差集为:"<<"["<<a<<","<<b<<"]"<<endl; } else if(c>b) { cout<<"交集为:空集"<<endl; cout<<"并集为:"<<"["<<a<<","<<b<<"]"<<","<<"["<<c<<","<<d<<"]"<<endl; cout<<"差集为:"<<"["<<a<<","<<b<<"]"<<endl; } else if(c<a) { int min,max; if(d>b) min=b,max=d;else min=d,max=b; cout<<"交集为:"<<"["<<a<<","<<min<<"]"<<endl; cout<<"并集为:"<<"["<<c<<","<<max<<"]"<<endl; if(d>=b) cout<<"差集为:空集"<<endl; else cout<<"差集为:"<<"["<<d-1<<","<<b<<"]"<<endl; } else { int min,max; if(d>b) min=b,max=d;else min=d,max=b; cout<<"交集为:"<<"["<<c<<","<<min<<"]"<<endl; cout<<"并集为:"<<"["<<a<<","<<max<<"]"<<endl; if(c<=a) cout<<"差集为:空集"<<endl; else { cout<<"差集为:"<<"["<<a<<","<<c-1<<"]"; if(d<b) { cout<<","<<"["<<d-1<<","<<b<<"]"; } cout<<endl; } } } return 0;} 望采纳,谢谢