Example 1
Input:
7
Output:
*1
21*
*123
4321*
*12345
654321*
*1234567
Example 2
Input:
2
Output:
*1
21*
#include<stdio.h>int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int a=i; for(int j=1;j<=i;j++) { (i%2==1&&j==1)&&(printf("*")); (i%2==1)&&(printf("%d",j)); (i%2==0)&&(printf("%d",a--)); (i%2==0&&j==i)&&(printf("*")); } printf("\n"); }}#include<stdio.h>int main() { char string[1001]; int len; scanf("%s%n",string,&len); int start=0,end=len-1; for(int i=0;i<len;i++) { for(int j=0;j<len;j++) { if(j==start||j==end) { printf("%c",string[j]); } else { printf(" "); } } start++; end--; printf("\n"); }}Example:
Input
4 5
80 50 45 86 20
48 57 10 44 30
22 47 58 44 27
74 36 84 40 99
Output:
80 50 45 86 44 44 40
48 57 10 58 84
22 47 36
74
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int mat[n][n];for(int row=1;row<=n;row++) for(int col=1;col<=n;col++) scanf("%d ",&mat[row][col]); int ctr=(n*2)-1,len=n;for(int i=1;i<=n;i++){ int a=i,b=1,k=0; for(int j=1;j<=ctr;j++) { printf("%d ",mat[a][b]); if(j%len==0) k=1; if(k==0) b++; else a++; } ctr=ctr-2; len--; printf("\n");}}