Skip to content

Instantly share code, notes, and snippets.

@jwon0615 jwon0615/1469.cpp
Created Mar 26, 2018

Embed
What would you like to do?
4_codeup_연습문제_배열
#include <stdio.h>
int main(void){
int n, arr[100][100];
scanf("%d",&n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
arr[i][j]= n*i+(i%2?j+1:n-j);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
printf("%d ", arr[i][j]);
printf("\n");
}
return 0;
}
#include <stdio.h>
int arr[102][102];
int main(){
int cnt,n,m;
scanf("%d %d",&n, &m);
cnt=n*m;
int x=n,y=1;
while(cnt>=1){
while(arr[x][y]==0&&x>0){
arr[x--][y]=cnt--;
}
x++,y++;
while(arr[x][y]==0&&y<=m){
arr[x][y++]=cnt--;
}
y--,x++;
while(arr[x][y]==0&&x<=n){
arr[x++][y]=cnt--;
}
x--, y--;
while(arr[x][y]==0&&y>0){
arr[x][y--]=cnt--;
}
y++,x--;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
}
#include<stdio.h>
int arr[51][51];
int main(){
int i, j, n, diff, cnt=1;
int s=0, e=-1;
scanf("%d", &n);
diff=n;
while(cnt<=n*n){
for(i=1;i<=diff;i++) arr[s][++e]=cnt++;
diff--;
for(i=1;i<=diff;i++) arr[++s][e]=cnt++;
for(i=1;i<=diff;i++) arr[s][--e]=cnt++;
diff--;
for(i=1;i<=diff;i++) arr[--s][e]=cnt++;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
printf("%d ", arr[i][j]);
printf("\n");
}
}
#include<stdio.h>
int arr[16][16];
int main(){
int i, j, n, diff, cnt=1;
int s=-1, e=0;
scanf("%d", &n);
diff=n;
while(cnt<=n*n){
for(i=1;i<=diff;i++) arr[++s][e]=cnt++;
diff--;
for(i=1;i<=diff;i++) arr[s][++e]=cnt++;
for(i=1;i<=diff;i++) arr[--s][e]=cnt++;
diff--;
for(i=1;i<=diff;i++) arr[s][--e]=cnt++;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
printf("%d ", arr[i][j]);
printf("\n");
}
}
#include<stdio.h>
int main(){
int a[21][21],i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",a+i);
for(i=1;i<n;i++)
for(j=1;j<=i;j++)
a[i][j]=a[i][j-1]-a[i-1][j-1];
for(i=0;i<n;i++){
for(j=0;j<=i;j++)
printf("%d ",a[i][j]);
printf("\n");
}
}
#include<stdio.h>
int main(){
int n,num=0,arr[50][50];
scanf("%d",&n);
int row=0,col=n/2;
while(num<=n*n){
arr[row][col]=++num;
if(num%n==0) row++;
else {
col++; row--;
if(col==n)col=0;
if(row==-1)row=n-1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) printf("%d ",arr[i][j]);
printf("\n");
}
}
int main(){
int arr[50][50],i,j,num=0,n;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
arr[(2*i-j+n)%n][(n/2-i+j+n)%n]=++num;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++) printf("%d ",arr[i][j]);
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.