class square
{
public:
square( float d = 0){radius = d}
float perimeter(float d)
{
return 4 * d
}
private:
float radius
}
abstract class shape {abstract double getCircumference()
}
class triangle extends shape {
private int a
private int b
private int c
triangle(int a, int b, int c) {
this.a = a
this.b = b
this.c = c
}
double getCircumference() {
if (a <= 0 | b <= 0 | c <= 0 | a + b <= c | b + c <= a | a + c <= b) {
return 0
}
return a + b + c
}
}
class square extends shape {
private int a
private int b
square(int a, int b) {
this.a = a
this.b = b
}
double getCircumference() {
if (a <= 0 | b <= 0) {
return 0
}
return (a + b) * 2.0
}
}
思路:输出正方形即输出正方形的外围就行,外围有个特点就陪谈历是行列下标必有0或侍陵者是正方形的大小减一,输入一个n表示正方形大小,输出一个由*组成的正方形。
参考代码:
#include <stdio.h>int main()
{
int i,j,n
scanf("%d",&n)
for(i=0i<ni++){
for(j=0j<nj++){
if(i==0||i==n-1||j==0||j==n-1)
printf("*")
else
printf(" "芦搜)
}
printf("\n")
}
return 0
}
/*
输出:
5
*****
* *
* *
* *
*****
*/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)