C++ Programming Blog

 
 
 

Image

 # include <iostream.h>
 # include <fstream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>

 int main( )
    {
       clrscr( );

       fstream File(\"CP-18.txt\",ios::in|ios::nocreate);

       if(!File)
      {
         cout<<\"\\n Unable to open the input file.\"<<endl;
         cout<<\"\\n Press any key to exit.\";

         getch( );
         exit(EXIT_FAILURE);
      }

       char Data[100]={NULL};

       int amplitude=0;
       int frequency=0;

       File.getline(Data,80);

       amplitude=atoi(Data);

       strset(Data,NULL);

       File.getline(Data,80);

       frequency=atoi(Data);

       File.close( );

       for(int i=1;i<=frequency;i++)
      {
         for(int j=1;j<=amplitude;j++)
        {
           for(int k=1;k<=j;k++)
              cout<<j;

           cout<<endl;
        }

         for(int l=(amplitude-1);l>=1;l--)
        {
           for(int m=1;m<=l;m++)
              cout<<l;

           cout<<endl;
        }

         if(i!=frequency)
        cout<<endl;
      }

       getch( );
       return 0;
    }