I need to write a program where it takes 2 integers from a file. Then it has to make a pyramid from those 2 numbers. It has to look like this:

I’ve wrote the code and it works as I want to, bet I can’t think of a way how make it look a pyramid like.
Here’s how it looks when I do it:

And this is my code:
#include <fstream>
using namespace std;
int main(){
ifstream inFile("Duomenys.txt");
ofstream outFile("Rezultatai.txt");
int N,M,smth,suma=0;
inFile >> N >> M;
smth=N;
while(N<=M){
for(int i=smth;i<=N;i++){
outFile<<i<<" ";
suma+=i;
if(i==N){
for(int i=N-1;i>=smth;i--){
outFile<<i<<" ";
suma+=i;
}
}
}
outFile<<endl;
N++;
}
outFile<<endl<<"Skaiciu suma: "<<suma;
inFile.close();
outFile.close();
return 0;
}
So my question would be, how to make it that my answer would be shaped in pyramid like in example?
1 Answer