How to Make an Asterisk Space Pattern in C++

How to Make an Asterisk Space Pattern in C++ thumbnail
Create your own pattern of asterisks and spaces with C++.

C++ is a programming language developed in 1983. It can be used to create all kinds of computer programs depending on the user's level of skill. One of the most common practice exercises when learning C++ is to generate different patterns using asterisks and spaces in order to grasp the concept of using the mathematical functions found in C++. The pattern changes shape based on the type of function placed in the code and can be drastically different if the user places a "+" sign where a "<=" sign used to be.

Instructions

    • 1

      Open your C++ code compiler. If you don't have one, try using Code::Blocks which you can download at Cprogramming.com (see Resource).

    • 2

      Copy and paste the following code into your compiler:

      #include<iostream>

      #include<cstdlib>

      using namespace std;

      int main()

      {
      int i=0, j=0, NUM=3;

      for(i=-NUM; i<=NUM; i++)
      {

      for(j=-NUM; j<=NUM; j++)

      {

      if( abs(i)+abs(j)==NUM) // Change this condition

      { cout<<"*"; }

      else { cout<<" ";}

      }

      cout<<endl;

      }
      return 0;
      }

    • 3

      Change the "+" and "==" symbols from the "//Change this condition" line to other mathematical symbols (<=, >=, etc) to produce other asterisk space patterns.

Related Searches:

References

Resources

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured