Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n;
- scanf("%d", &n);
- int rowNeed = 0;
- int colNeed = 0;
- int i;
- // get number of coll.
- for(i=n; i>1; i--){
- colNeed ++;
- }
- colNeed = colNeed*2;
- colNeed ++;
- // the row and the col. number is tha same in every case
- rowNeed = colNeed;
- //print
- int col, row;
- int mid = colNeed/2;
- int hat = n;
- int ir;
- int f;
- int d;
- for(row=0; row<rowNeed; row++){
- ir = n;
- f=-1;
- d=0;
- for(col=0; col<colNeed; col++){
- if(col<=mid){
- if(ir>hat){
- printf("%d ", ir);
- ir -= 1;
- }
- else if(ir==hat){
- printf("%d ", hat);
- f++;
- }
- }
- else if(col>mid){
- if(d<f){
- printf("%d ", hat);
- d++;
- }
- else{
- ir++;
- printf("%d ",ir);
- }
- }
- }
- if(row<mid){
- hat--;
- }
- else{
- hat++;
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement