二、设计思路、
1.先输出前两个月的兔子数,然后进入循环
2.循环中每过一个月都会有新兔子产生,迭代求出当前月份的兔子数
3.求和输出每个月的兔子总数
三、程序流程图
四、代码实现
#include<stdio.h> using namespace std; int main() { long rab1 = 1, rab2 = 1, rab; int i; for(i=1;i<=15;i++) { printf("%12d%12d", rab1, rab2); if(i%2==0) printf("\n"); rab1=rab1+rab2; rab2=rab1+rab2; } return 0; }
#include<bits/stdc++.h> #define PI 3.14159 using namespace std; class Shape{ }; //圆形 class Circle :public Shape{ double R; public: Circle(double r):R(r){} void Area(){ printf("%.2f\n",PI*R*R); } }; //矩形 class Rectangle:public Shape{ double X,Y; public: Rectangle(double x,double y):X(x),Y(y){} void Area(){ printf("%.2f\n",X*Y); } }; //三角形 class Triangle:public Shape{ double L,H; public: Triangle(double h,double l):H(h),L(l){} void Area(){ printf("%.2f\n",L*H/2); } }; int main(){ double r,x,y,h,l; cin>>r>>x>>y>>h>>l; Circle c1(r); Rectangle c2(x,y); Triangle c3(h,l); c1.Area(); c2.Area(); c3.Area(); return 0; }
标签:Area,int,double,public,Shape,打卡,4.24,class From: https://www.cnblogs.com/binglinll/p/17347361.html