Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- int matrica[100][100];
- int results[100][100];
- int m,n;
- int i,j;
- int k,z;
- scanf("%d%d",&m,&n);
- scanf("%d%d",&k,&z);
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++){
- scanf("%d",&matrica[i][j]);
- }
- }
- if(k>0)
- {
- //shift na redici nadole
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- if(i<k)
- {
- results[i][j]=0;
- }
- else{
- results[i][j]=matrica[i-k][j];
- }
- }
- }
- }
- else if(k<0)
- {
- //shift na redici nadole
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- if(i>=k*(-1)){
- //ili fabs(k)
- results[i][j]=0;
- }
- else{
- results[i][j]=matrica[i-k][j];
- }
- }
- }
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- matrica[i][j]=results[i][j];
- }
- }
- if(z<0)
- {
- //shift na koloni na levo
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- if(j>=z*(-1))
- {
- results[i][j]=0;
- }else{
- results[i][j]=matrica[i][j-z];
- }
- }
- }
- }
- else if(z>0)
- {
- //shift na koloni na desno
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- if(j<z){
- results[i][j]=0;
- }else{
- results[i][j]=matrica[i][j-z];
- }
- }
- }
- }
- }
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++){
- printf("%d ",results[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment