Program to print pi pattern in C++

In this post, we are going to learn a program to print pi patterns in C++. In this article, we will see the pattern that is of the shape of pi.

Program to print pi pattern in C++

#include <iostream>
using namespace std;

int main() {
    char arr[]= "5'I+GJGKOHLKIKNOMOIHINJLHLJIINIHMO 3'KFHNNJGOMGLOIOOIMKGFKNHFOMJOJJKOHI 2'FMNGLJFLHNLHFNOONLHNFIJNHKIJHGGMFLM 2'ONHG4'JNFNL9'KGIH9' 1'NHI6'FLLJM8'FOINJ9' JL8'FOKKF8'KNHHI9' GM8'HKIKO8'JFNG10' 10'HNJN9'GGGM10' 10'JKFH9'NJGF10' 10'HMFG9'OINK10' 9'HGGFK8'KKOLJ10' 9'JLHHO8'JNOKJ10' 9'OIFI9'NGOLJ10' 9'JHNN9'GFOMK10' 8'LLKOI9'IJJLG10' 7'HNJMKL9'JNHII10' 7'MNLMN10'IGLKH8'MG 6'HFGOFOG9'JKLJNK7'LL 5'OHIJLFI11'JNLGFJKJIHLLJN 4'HGIIOIL12'FMHLFHJOGJGHM1' 4'IMHJKNM13'FFLLFLIGKKN2' 4'NGMJNN15'GKHFOHFOL";
    int x,y,k,val=0;
    for(x=0;x<493;x++){
        if((arr[x]>='F' && arr[x]<='O') || arr[x]==' '){
            y=arr[x];
            y-=22;
            cout<<(char)y;
        }
        else if(arr[x]=='+'){
            y=arr[x];
            y+=3;
            cout<<(char)y;
        }
        else if(arr[x]>='0' && arr[x]<='9'){
            while(arr[x]!='\''){
                k=arr[x];
                k-=48;
                x++;
                val=val*10+k;
            }
            y=arr[x];
            y-=7;
            for(int l=1;l<=val;l++){
                cout<<(char)y;
            }
        }
        val=0;
    }
    return 0;
}

Output

     3.141592653589793238462643383279
   5028841971693993751058209749445923
  07816406286208998628034825342117067
  9821    48086         5132         
 823      06647        09384         
46        09550        58223         
17        25359        4081          
          2848         1117          
          4502         8410          
          2701         9385          
         21105        55964          
         46229        48954          
         9303         81964          
         4288         10975          
        66593         34461          
       284756         48233          
       78678          31652        71
      2019091         456485       66
     9234603           48610454326648
    2133936            0726024914127 
    3724587             00660631558  
    817488               152092096