squa函数c语言 c语言srand函数的用法
C语言编程题~~选几个做出了给我吧~~看着我混乱了啊~用C程序哦~c++。。。
35题:
临夏网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联从2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
#include stdio.h
main()
{
int i, sum=0;
for(i=1; i50; i=i+2)
sum += i * (i+1);
printf("result=%d\n", sum);
}
38题:
#include stdio.h
main()
{
int a[10], i, sum=0, squaresum=0;
printf("please input 10 number:");
scanf("%d %d %d %d %d %d %d %d %d %d", a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]);
for(i=0; i10; i++)
{sum += a[i]; squaresum += a[i]*a[i];}
printf("sum=%d sum of squaue=%d\n", sum, squaresum);
}
用C++编写一个程序,定义抽象基类Shape,由它派生出5个派生类:Cricle(圆形),Squa
#include iostream
using namespace std;
class Shape //定义抽象基类 Shape
{
public:
virtual double area() const =0; //纯虚函数
};
class Circle:public Shape
{
public:
Circle(double r):radius(r){} //构造函数
virtual double area() const //定义虚函数
{
return 3.14159*radius*radius;
};
protected:
double radius;
};
class Square:public Shape //定义 Square(正方形)类
{
public:
Square(double s):side(s){}
virtual double area() const {return side*side;}//定义虚函 数
protected:
double side;
};
class Rectangle:public Shape //定义 Rectangle(矩形)类
{
public:
Rectangle(double w,double h):width(w),height(h){}//构造函数
virtual double area() const {return width*height;}//定义虚函数
protected:
double width,height;
};
class Trapezoid:public Shape //定义 Trapezoid(梯形)类
{
public:
Trapezoid(double t,double b,doubleh):top(t),bottom(t),height(h){} //构造函数
virtual double area() const {return0.5*(top+bottom)*height;} //定义虚函数
protected:
double top,bottom,height;//上底、下底与高
};
class Triangle:public Shape//定义 Triangle(三角形)类
{
public:
Triangle(double w,double h):width(w),height(h){}//构造函数
virtual double area() const {return 0.5*width*height;} //定义虚
protected:
double width,height;
};
int main()
{
Circle circle(12.6);//建立Circle 类对象 circle
Square square(3.5);//建立Square 类对象 square
Rectangle rectangle(4.5,8.4);//建立Rectangle 类对象 rectangle
Trapezoid trapezoid(2.0,4.5,3.2);//建立 Trapezoid 类对象 trapezoid
Triangle triangle(4.5,8.4);//建立Triangle 类对象
Shape *pt[5]={circle,square,rectangle,trapezoid,triangle}; //定义基类指针数组 pt,使它每一个元素指向一个派生类对象
double areas=0.0;//areas 为总面积
for(int i=0;i5;i++)
{
areas=areas+pt[i]-area();
}
cout"totol of all areas="areasendl; //输出总面积
return 0;
}
C语言作业,求帮忙,谢谢!
#include stdio.h
int main(void)
{
int num=1;
int squa=0;
printf("number\tsquare\n");
for(num=1;num=100;num++)
{
squa=(num*num);
if(squa/100)
{if(squa%10==squa/100)
printf("%d\t%d\n",num,squa);}
else if(squa/10)
{if(squa%10==squa/10)
printf("%d\t%d\n",num,squa);}
else if(squa0squa10)
printf("%d\t%d\n",num,squa);
}
return 0;
}
调好的
运用C++语言编写一个多边形基类,再写两个子类,每个子类都要计算计算周长和面积。
1.h 如下:
#include math.h
class CPolygon {
protected:
int length;
public:
void set_values (int a) {length=a;}
virtual int perimeter(void){return 1;}
virtual double area(void){return 1;}
};
class CSquare: public CPolygon {
public:
int perimeter(void){return length*4;}
double area (void){ return (length * length); }
};
class CTriangle: public CPolygon {
public:
int perimeter(void){return length*3;}
double area (void){ return (length * length * sqrt(3) / 4); }
};
2.cpp 如下:
#include iostream.h
#include "1.h"
int main () {
CSquare squa;
CTriangle trgl;
squa.set_values (4);
trgl.set_values (4);
cout squa.area() endl;
cout trgl.area() endl;
return 0;
}
当前标题:squa函数c语言 c语言srand函数的用法
文章源于:http://myzitong.com/article/doesoco.html