Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10], n, i, j,s=0,p=1;
- scanf("%d",&n);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- if (j<i)
- s=s+a[i][j];
- else
- if (i<j)
- p=p*a[i][j];
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("S= %d, P= %d",s,p);
- }
- //2. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,min,max,n,pom,maxi,mini,maxj,minj;
- scanf("%d",&n);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- mini=1;
- minj=0;
- maxi=0;
- maxj=1;
- min=a[1][0];
- max=a[0][1];
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- if (i>j && a[i][j]<min)
- {
- min=a[i][j];
- maxi=i;
- maxj=j;
- }
- else
- if (j>i && a[i][j]>max)
- {
- max=a[i][j];
- maxi=i;
- maxj=j;
- }
- pom=a[maxi][maxj];
- a[maxi][maxj]=a[mini][minj];
- a[mini][minj]=pom;
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- }
- //3. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,min,max,n,m,mini=0,maxi=0,pom;
- scanf("%d%d",&n,&m);
- for (i=0;i<n;i++)
- for (j=0;j<m;j++)
- scanf("%d",&a[i][j]);
- min=a[0][0];
- max=a[0][0];
- for (i=0;i<n;i++)
- for (j=1;j<m;j++)
- if (a[i][j]<min)
- {
- min=a[i][j];
- mini=i;
- }
- else
- if (a[i][j]>max)
- {
- max=a[i][j];
- maxi=i;
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- pom=a[mini][i];
- a[mini][i]=a[maxi][i];
- a[maxi][i]=pom;
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- }
- //4. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,n,m,pom,k;
- scanf("%d%d",&n,&m);
- for (i=0;i<n;i++)
- for (j=0;j<m;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- k=m-1;
- for (j=0;j<m/2;j++)
- {
- pom=a[i][j];
- a[i][j]=a[i][k];
- a[i][k]=pom;
- k=k-1;
- }
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- }
- //5. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,m,n,s,mini,min=0;
- scanf("%d%d",&n,&m);
- for (i=0;i<n;i++)
- for (j=0;j<m;j++)
- scanf("%d",&a[i][j]);
- mini=0;
- for (i=0;i<n;i++)
- min=min+a[i][0];
- for (j=1;j<m;j++)
- {
- s=0;
- for (i=0;i<n;i++)
- s=s+a[i][j];
- if (s<min)
- {
- mini=j;
- min=s;
- }
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- printf("%d ",a[i][mini]);
- }
- //6. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,n,k,z,g=0,pom,c;
- scanf("%d%d",&n,&k);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- g=0;
- for (j=0;j<n;j++)
- if (j>i && g==0)
- {
- for (c=0;c<k;c++)
- {
- pom=a[i][n-1];
- for (z=n-1;z>i+1;z--)
- a[i][z]=a[i][z-1];
- a[i][j]=pom;
- }
- g=1;
- }
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- }
- //7. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,n,m,b[10][10];
- scanf("%d%d",&n,&m);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- b[i][j]=a[i][j]-2*a[j][i];
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[j][i]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",b[i][j]);
- printf("\n");
- }
- }
- //8. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,m,n,b;
- scanf("%d%d",&n,&m);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- {
- for (j=0;j<m;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- {
- b=0;
- for (j=0;j<m-1;j++)
- if (a[i][j]<=a[i][j+1])
- b++;
- if (b==m-1)
- printf("%d ",i);
- }
- }
- //9. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],i,j,n,z,g,pom;
- scanf("%d",&n);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- if (i+j==n-1)
- for (z=i+1,g=j-1;z<n;z++,g--)
- if (a[i][j]<a[z][g])
- {
- pom=a[i][j];
- a[i][j]=a[z][g];
- a[z][g]=pom;
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- }
- //10. ZADATAK
- #include <stdio.h>
- main()
- {
- int a[10][10],b[10],i,j,n,z=0;
- scanf("%d",&n);
- for (i=0;i<n;i++)
- for (j=0;j<n;j++)
- scanf("%d",&a[i][j]);
- for (i=0;i<n;i++)
- b[i]=a[i][i];
- for (i=n-1;i>=0;i--)
- for (j=0;j<n;j++)
- if (i+j==n-1)
- {
- b[z]=b[z]+a[i][j];
- z++;
- }
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- printf("%d ",a[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i=0;i<n;i++)
- printf("%d ",b[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement