第一题
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e1a803c114ccaee9b9be8d95fba5dd27.png)
#include"stdio.h"
int count(int x){
int sum,i;
sum=1;
for(i=2;i<x;i++){
if(x%i==0)
sum += i;
}
return sum;
}
int main(){
int i;
for(i=1;i<=10000;i++){
if(i==count(i))
printf("%2d,",i);
}
return 0;
}
第二题
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d329bf79142c6b422a610cd8c9ec3f85.png)
#include"stdio.h"
#include"math.h"
int is_threeANgle(int a,int b,int c){
if(a+b>c && a+c>b && b+c>a)
return 1;
else return 0;
}
int main(){
int a,b,c,s;
double area;
printf("输入三条边:");
scanf("%d %d %d",&a,&b,&c);
if(is_threeANgle(a,b,c)){
if(a==b &&b==c)
printf("等边三角形\n");
else if(a==b || a==c || b==c)
printf("等腰三角形\n");
else if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)
printf("直角三角形\n");
else printf("一般三角形\n");
s=(a+b+c)/2;
area=sqrt((double)s*(s-a)*(s-b)*(s-c));
printf("三角形面积:%f\n",area);
}
else printf("不能组成三角形\n");
return 0;
}
第三题
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e3e5164758564c8cbe8b4406999ea02b.png)
#include"iostream"
using namespace std;
class vehicle {
protected:
int wheels;
float weight;
public:
void init(int wheels,float weight);
float get_weight();
int get_wheels();
void print();
};
void vehicle::init(int wheels,float weight){
this->wheels=wheels;
this->weight=weight;
}
float vehicle::get_weight(){
return this->weight;
}
int vehicle::get_wheels(){
return this->wheels;
}
void vehicle::print(){
cout<<"车轮数:"<<this->wheels<<"重量:"<<this->weight<<endl;
}
class car:public vehicle {
private:
int passenger;
public:
void init(int wheels,float weight,int passenger);
int get_passenger();
void print();
};
void car::init(int wheels,float weight,int passenger){
this->wheels=wheels;
this->weight=weight;
this->passenger=passenger;
}
int car::get_passenger(){
return this->passenger;
}
void car::print(){
cout<<"车轮数:"<<this->wheels<<"重量:"<<this->weight<<"载人数:"<<this->passenger<<endl;
}
int main(){
car c;
c.init(4,200,4);
c.print();
return 0;
}