In: Computer Science
code:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
int n; //declaring the variables
ifstream input_diamond;
ofstream output_diamond;
input_diamond.open("input_diamond.txt",ios::in); //opening the
input file
output_diamond.open("output_diamond.txt",ios::out); //creating the
output file
input_diamond>>n; //assigning input file value to the n
for(int i=1;i<=n;++i){
for(int j=1;j<=2*i-1;++j){
output_diamond<<"*"; //printing the * in output file
}
output_diamond<<"\n";
}
for(int i=n-1;i>=0;i--){
for(int j=1;j<=2*i-1;++j){
output_diamond<<"*";
}
output_diamond<<"\n";
}
output_diamond.close();
}
output: