0

Can anybody help me with this.. we are to make a diamond pattern of asterisk..I had the codes below..My problem is.. we are only allowed to use one asterisk and one space to make the program and inside the diamond pattern we are to put the letters A,B, and C..
Can anyone pls...

#include <iostream.h>
#include <math.h>
#include<conio.h>
void main (void)
{

	int r,c,s;
	int space,asterisk;
    asterisk=1;
	space = 7/2+1;

	for(r=1;r<=7;r++)
	{

		//for the spacing
			for(s=0;s<space;s++)
			{
				cout << " ";
			}

		for(c=asterisk;c>0;c--)
		{						

			if(r==4)
			{
				if(c==3)
				{
					cout << "L";
				}else if(c==4)
				{
					cout << "V";
				}else if(c==5)
				{
					cout << "A";
				}else
				{
					cout << "*";
				}	
				
			}else{
				cout << "*";
			}
		}

		//to check each line and compute how many asterisk and spaces to display
		if(r>=4){
			asterisk = asterisk - 2;
			space ++;
		}else{
			asterisk= asterisk + 2;
			space --;
		}
		
		//to proceed to the next line
		cout << "\n";
	}

	
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by VernonDozier
0

Can anybody help me with this.. we are to make a diamond pattern of asterisk..I had the codes below..My problem is.. we are only allowed to use one asterisk and one space to make the program and inside the diamond pattern we are to put the letters A,B, and C..
Can anyone pls...

#include <iostream.h>
#include <math.h>
#include<conio.h>
void main (void)
{

	int r,c,s;
	int space,asterisk;
    asterisk=1;
	space = 7/2+1;

	for(r=1;r<=7;r++)
	{

		//for the spacing
			for(s=0;s<space;s++)
			{
				cout << " ";
			}

		for(c=asterisk;c>0;c--)
		{						

			if(r==4)
			{
				if(c==3)
				{
					cout << "L";
				}else if(c==4)
				{
					cout << "V";
				}else if(c==5)
				{
					cout << "A";
				}else
				{
					cout << "*";
				}	
				
			}else{
				cout << "*";
			}
		}

		//to check each line and compute how many asterisk and spaces to display
		if(r>=4){
			asterisk = asterisk - 2;
			space ++;
		}else{
			asterisk= asterisk + 2;
			space --;
		}
		
		//to proceed to the next line
		cout << "\n";
	}

	
}

By this:

inside the diamond pattern we are to put the letters A,B, and C..

do you mean the result is to be something like this?

*
  *C*
 *BCB*
*ABCBA*
 *BCB*
  *C*
   *
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.