Pattern issue
need help in getting the following pattern
123454321
1234 4321
123 321
12 21
1 1
I worte the code but getting the following output
123454321
123454321
123454321
123454321
123454321
please find my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k;
clrscr();
cout<<"Enter the number of lines : ";
cin>>k;
for(i=1;i<=k;i++)
{
for(j=1j<=k;j++)
cout<<j;
for(m=k-1;m>k;m--)
cout<<m;
cout<<endl;
}
getche();
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
int main()
{
int j,k,l;
cout << "Enter the number of lines : ";
cin >> j;
for(; j>0; j-- )
{
for(k = 1; k <= j; k++)
{
cout << k;
}
for(l = j-1; l>0; l--)
{
cout << l;
}
cout << endl;
}
return 0;
}
|
I'm not sure if this is the pattern or formatting you need but compile it and see what you can do to suit it to your needs.
Hope this helps.
Topic archived. No new replies allowed.