c++第六次上机实验——作业
2016-05-20 11:32
239 查看
第二题:
#include <iostream>
using namespace std;
void main()
{
int x,y,a,d;
for(x=1000;x<=10000;x++)
{
a=x/1000;
d=x%10;
for(y=2;y<x;y++)
{
if(x%y==0)break;
}
if(x==y)
{
if(a==d)
cout<<x<<" ";
}
}
}
运行结果:
![](https://img-blog.csdn.net/20160520113037227?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
第五题:
#include <iostream>
using namespace std;
void main()
{
int x,y,z;
for(x=0;x<=20;x++)
{
for(y=0;y<=33;y++)
{
for(z=0;z<=300;z++)
{
if(5*x+3*y+z/3==100&&x+y+z==100)
cout<<"鸡翁"<<x<<"只"<<","<<"鸡母"<<y<<"只"<<","<<"鸡雏"<<z<<"只"<<endl;
}
}
}
}
运行结果:
#include <iostream>
using namespace std;
void main()
{
int x,y,a,d;
for(x=1000;x<=10000;x++)
{
a=x/1000;
d=x%10;
for(y=2;y<x;y++)
{
if(x%y==0)break;
}
if(x==y)
{
if(a==d)
cout<<x<<" ";
}
}
}
运行结果:
第五题:
#include <iostream>
using namespace std;
void main()
{
int x,y,z;
for(x=0;x<=20;x++)
{
for(y=0;y<=33;y++)
{
for(z=0;z<=300;z++)
{
if(5*x+3*y+z/3==100&&x+y+z==100)
cout<<"鸡翁"<<x<<"只"<<","<<"鸡母"<<y<<"只"<<","<<"鸡雏"<<z<<"只"<<endl;
}
}
}
}
运行结果: