C++输出菱形,找下错误!

来源:百度知道 编辑:UC知道 时间:2024/06/28 03:21:42
#include <iostream.h>
void printstars(int blanks,int stars);
int main()
{
int numofline;
int countline;
int numofblanks;
int starsinline;
cout<<"please input the odd number of diamond lines(1 to 25)";
cout<<"to be printed!"<<endl;
cin>>numofline;
while(numofline<=0||numofline>25||(numofline%2)==0)
{
cout<<"Number of diamond's lines should be between 1 and 25";
cout<<"and it must be a odd number!";
cout<<"please input the odd number of diamond lines(1 to 25)";
cout<<"to be printed"<<endl;
cin>>numofline;
}
cout<<endl;
numofblanks=30;
for(countline=1;countline<=(numofline/2+1);countline++)
{
starsinline=countline;
printstars(numofblanks,starsinline);
numofblanks--;
}
for(;countlin

程序我加了一行,你看一下,你的程序貌似第一次运行比较慢!
#include <iostream.h>
void printstars(int blanks,int stars);
int main()
{
int numofline;
int countline;
int numofblanks;
int starsinline;
cout<<"please input the odd number of diamond lines(1 to 25)";
cout<<"to be printed!"<<endl;
cin>>numofline;
while(numofline<=0||numofline>25||(numofline%2)==0)
{
cout<<"Number of diamond's lines should be between 1 and 25";
cout<<"and it must be a odd number!";
cout<<"please input the odd number of diamond lines(1 to 25)";
cout<<"to be printed"<<endl;
cin>>numofline;
}
cout<<endl;
numofblanks=30;
for(countline=1;countline<=(numofline/2+1);countline++)
{
starsinline=countline;
printstars(numofblanks,starsinline);
numof