1 2 3 4 5 16 6 15 7 14 8 13 12 11 10 9
int main()
{
int i,j,k=6,l=13,m=16;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(i==1)
printf("%-3d",j);
else if(j==5)
printf("%-3d",k++);
else if(i==5)
printf("%-3d",l--);
else if(j==1)
printf("%-3d",m--);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
Can someone help in writing the above code using arrays ?
ReplyDelete// trying the thoughtworks lab pattern
ReplyDelete#include
#include
using namespace std;
int main()
{
cout << "Hello world! enter the number for the patter " << endl;
int n;
cin>> n;
int arr[n][n];
int a=1;
int b=(2*n)+(2*(n-2));
int c=(n);
int d=((2*n)+(n-2));
//*************
for(int i =0; i <n; i++)
{
for(int j =0; j <n; j++)
{
arr[i][j]=0;
}}
//************
for(int i =0; i <n; i++)
{
for(int j =0; j <n; j++)
{
if(i==0)
{
arr[i][j]=a++;
}
if(j==0&&i!=0)
{
arr[i][j]=b;
b--;
}
if(j==(n-1))
{
arr[i][j]=c;
c++;
}
if(i==(n-1))
{
arr[i][j]=d;
d--;
}
else{arr[i][j]==0;}
}
}
int k=0;
for(int i =0; i <n; i++)
{
for(int j =0; j <n; j++)
{
cout<<setw(5)<<arr[i][j];
if(j==(n-1))
{
cout<<endl;
}
}
}
return 0;
}
Please write a code that could be understandable..
DeleteThe code is in java:
ReplyDeletebut will work in c++ as well just replace System.out.print("") by print()
int a[][] = new int[m][n];
int k=0;
for(int i=0; i=0 ; i--)
a[n-1][i] = ++k;
for(int i=m-2 ; i>0 ; i--)
a[i][0] = ++k;
for(int i=0; i<m; i++){
for(int j=0; j<n ;j++)
System.out.print(a[i][j] + " ");
System.out.println("");
}
Simple code:
ReplyDeleteint main()
{
int i,j,k,l,p,n;
n=8;
p=n+1;
k=n+n+n-2;
l=k+n-2;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==1)
printf("%-3d",j);
else if(j==n)
printf("%-3d",p++);
else if(i==n)
printf("%-3d",k--);
else if(j==1)
printf("%-3d",l--);
else
printf(" ");
}
printf("\n");
}
return 0;
}
#include
ReplyDeleteusing namespace std;
int main()
{
int a=6,b=13,c=16;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
if(i==1){cout<<j<<" ";}
else if(j==5){cout<<a<<" ";a++;}
else if(i==5){cout<<b<<" ";b--;}
else if(j==1){cout<<c<<" ";c--;}
else cout<<" ";
}
cout<<endl;
}
return 0;
}
Uscorac0gilhi_Anchorage Ryan Vance https://marketplace.visualstudio.com/items?itemName=pioresuage.Descargar-Orb-Overload-gratuita-2022
ReplyDeletekrispersnecho
Ycomptasato1996 Anthony Baum Free Download
ReplyDeletesturatnachild
conccorXcomp_ri Kevin Price click here
ReplyDeleteclick
https://colab.research.google.com/drive/1KcSj0OIm5e6DhxqT3iK77VGOZROnozQV
download
incanmipost
carceFhau-ra-1993 Penny Brooks click
ReplyDeleteLink
That
odadntegmye
Aininsupp-shiSpringfield Melanie Mccallister Download Free
ReplyDeleteClick here
click
pitslagardsa