Matrix68. Given an M × N matrix and an integer K (1 ≤ K ≤ M). Before the row of the matrix with the number K insert a row of zeros.

program ZZ integer, allocatable, dimension(:,:)::A, B integer::m, n, k, x, y print*,'Enter M' read*,m print*,'Enter N' read*,n print*,'Enter K' read*,k allocate(a(m,n),b(m,n+1)) do y=1,n+1 read*,(a(x,y),x=1,m) end do do y=1,nb(k+1,y)=0 end do if(1<=k.and.k<=m)then do x=1,m do i=1,kb(x,i)=a(x,i) end do end do do x=k+2,n+1 b(x,i)=a(x,i-1) end do else do y=1,n print*,a(x,y) end do end if do i=1,n+1 print*,b(x,i) end do end program 

Closed due to the fact that off-topic participants jfs , ixSci , PashaPash , romeo , Athari 10 May '15 at 1:10 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "Questions asking for help with debugging (" why does this code not work? ") Should include the desired behavior , a specific problem or error, and the minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, complete, repeatable example . " - jfs, ixSci, romeo, Athari
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • @ Chingiz Bostanov, Format your code. This contributes to a more complete understanding of the task. - Nicolas Chabanovsky

1 answer 1

A little bit wrong. If k is in the set [1, m], then all the same cycles will look like this.

 read*,m print*,'Enter N' read*,n print*,'Enter K' read*,k if(1<=k.and.k<=m)then allocate(a(m,n),b(m+1,n)) do y=1,n+1 read*,(a(x,y),x=1,m) end do do y=1,n b(k,y)=0 end do do x=1,k-1 do y=1,n b(x,y)=a(x,y) end do end do do x=k,m do y=1,n b(x+1,y)=a(x,y) end do end do end if rem Дальше идет вывод на печать 

You get confused with array indices all the time. Here you have to be a little more careful.

  • Thanks for the correction. But I didn’t do that, he doesn’t do what I want. ( - Goldy
  • Given an M × N matrix and an integer K (1 ≤ K ≤ M). Before the row of the matrix with the number K insert a row of zeros. - Ie you need to copy the first to K-1 rows from the first table, then insert a row of zeros and copy the remaining rows. What did I understand wrong? - ichbinkubik
  • In general, the task passed all forwarded everything works. - Goldy