65 695
Assignments Done
99,2%
Successfully Done
In October 2018

Answer to Question #49737 in C++ for vasanth

Question #49737
I want to make a program to display following pattern
3
2 3 2
2 3 4 3 2
2 3 4 5 4 3 2
Expert's answer
#include<stream.h>
#include<conio.h>
 
int main()
{
    int n=5,i,j;
    cout<<"3\n";
    for(j=3;j<=n;j++)
    {
     for(i=2;i<j;i++)
        cout<<i<<" ";
     for(i=j;i>=2;i--)
        cout<<i<<" ";
     cout<<endl;
    }
    getch();
    return 1;
      
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
06.01.15, 14:19

#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
    int w=5;
    cout.width(w);
    cout.setf(ios::right);
    int n=5,i,j;
    cout<<"      3\n";
    for(j=3;j<=n;j++)
    {
     cout.width(w++);
     for(i=2;i<j;i++)
        cout<<i<<" ";
     for(i=j;i>=2;i--)
        cout<<i<<" ";
     cout<<endl;
     w=w-3;
    }
    getch();
    return 1;
}



vasanth
11.12.14, 15:01

the question which i asked actually has 4 space in first line and 3 space in second line and 2 space in third line. please can u give the code of the then programe

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions