Home > Back-end >  C output diamond
C output diamond

Time:05-20



Hope to be able to make the input a number
Generate corresponding to the number of lines of the diamond, because just learning c + +, if use a for loop hope to explain the detailed point! thank you

CodePudding user response:

Reference:
 # include 

Int main ()
{
Int I, j, n.
Printf (" Enter Odd_rows n: ");
The scanf (" % d ", & amp; N);
N=(n + 1)/2;

for(i=0; IFor (j=I; JPrintf (" ");
for(j=0; JPrintf (" * ");
printf("\n");
}
For (I=n - 2; I>=0; I -) {//diamond lower
For (j=I; JPrintf (" ");
for(j=0; JPrintf (" * ");
printf("\n");
}

return 0;
}

//Enter Odd_rows n: 5
//*
//* *
//* * *
//* *
//*
//please press any key to continue...


//Enter Odd_rows n: 9
//*
//* *
//* * *
//* * * *
//* * * * *
//* * * *
//* * *
//* *
//*
//please press any key to continue....
  • Related