HOW TO MAKE A HOLLOW DIAMOND IN C.
Here is the 1st algorithm in c language.
if you want any algorithm or program to understand and want a source code then let me know in the comments and if you want a video on it then also let me know in the comments.
this is your output!! |
the first star is printed on half of the inputted rows that's why k=rows/2 but,
if rows are even then subtract 1 to get the middle index i.e
if rows=6 then k=(6-1)/2= 2.5 (but the compiler will ignore everything after the point because the datatype is int).
and if rows is odd then we don't have to subtract one.
the diamond is 2d shape so nested loops are required.
if(j==((totalrows-1)/2)+i || j==((totalrows-1)/2)-i )
for printing stars .
and similarly the lower portion is drawn .
guys if you want to understand it by the video then let me know in the comments.
subscribe for more coding algos and if you have any questions then drop them in the comment section!!!
codesInStyle
so simple!!
ReplyDeletethanks David!
Delete