留服领取生活费:C++简单编程题~~~

来源:百度文库 编辑:高校问答 时间:2024/05/10 19:30:21
void Edge(int x);
this function prints two '*'s at the two ends with (x-2) spaces apart.

void Height(int x, int y);
this function prints the two vertical lines of a box with (x-2) spaces apart. The height of the vertical lines is y.
Hint: Call function Edge( ) y times, with the value of x passed in to Edge( ), to print the height of the box. You need a for loop!!

Sample dilog:
Please enter the wodth and height of the box : _15__5__

**************
* *
* *
* *
**************
谢谢1楼,我试试看...成功的话再把分给你
也谢谢2楼~我试试,还有就是for(;x>=0;x--)里面X的初始值是多少

楼上的不一定搞的定哦呵呵,
刚才的我的也搞不定呵呵,再再修改如下,VC6测了一下,搞定了~:

#include <stdio.h>

void Edge(int x)
{
for(;x>0;x--)
printf("*");
printf("\n");
}
void Line(int x)
{
printf("*");
for(;x>0;x--)
printf(" ");
printf("*\n");
}
void height(int x,int y)
{
y-=2;
Edge(x);
for(;y>0;y--)
{
Line(x-2);
}
Edge(x);
}

void main()
{
int x,y;
scanf("%d %d",&x,&y);
height(y,x);
}

void Edge(int x)
{
for(;x>=0;x--)
printf("*");
printf("\n");
}
void height(int x,int y)
{
int i;
Edge(x);
for(i=y-2;i<=y;i=i++)
{
printf("**\n");
}
Edge(x);
}