Sep 11, 2016 at 5:28am UTC
#include <stdio.h>
#include <stdlib.h>
int main() {
int n=2;
int i;
int j;
int suma =0;
int p;
int s1=0;
int s2=0;
while (n % 2 == 0) {
printf("Numarul n este:");
scanf( "%d", &n);
}
printf("n este:%d\n", n);
int m[n][n];
for (i = 0; i< n;i++)
for (j=0;j<n;j++) {
printf("m[%d][%d]= ",i,j);
scanf ("%d", &m[i][j]);
}
printf("\n");
for (i = 0; i< n;i++){
for (j=0;j<n;j++)
printf ("%d ", m[i][j]);
printf("\n");}
printf("\n");
//suma margini
j=0;
for (i = 0; i< n;i++){
suma= suma +m[i][j]; }
j=n-1;
for (i = 0; i< n;i++){
suma= suma+m[i][j];}
i=0;
for (j=0;j<n;j++){
suma= suma+m[i][j];}
i=n-1;
for (j=0;j<n;j++){
suma= suma+m[i][j];}
suma= suma -m[0][0]-m[0][n-1]-m[n-1][n-1]-m[n-1][0];
printf("suma este:%d\n",suma);
printf("\n");
//diagonale || cu principala
p=1;
while(p !=n){
for (i = p; i< n;i++)
printf("%d ", m[i-p][i]);
printf("\n");
p++;
}
p=1;
while(p !=n){
for (i = p; i< n;i++)
printf("%d ", m[i][i-p]);
printf("\n");
p++;
}
//cea mai mare suma pt diagonale || cu principala
p=1;
while(p !=n){
s1=0;
for (i = p; i< n;i++){
s1= s1+ m[i-p][i];
}
p++;
if (s2<s1)
s2 = s1;
}
p=1;
while(p !=n){
s1=0;
for (i = p; i< n;i++){
s1= s1+ m[i][i-p];
}
p++;
if (s2 < s1)
s2 = s1;
}
printf("suma maxima este: %d\n", s2);
return 0;
}
Sep 11, 2016 at 5:29am UTC
Please edit your post and make sure your code is [co de]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
You marked your topic as solved and didn't ask a question - do you want help?
Sep 11, 2016 at 5:31am UTC
#include <stdio.h>
#include <stdlib.h>
int main () {
int mat[3][3];
int i;
int j;
int cont=0;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++){
printf("m[%d][%d]= ", i ,j);
scanf("%d", &mat[i][j]);}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%d ",mat[i][j]);
printf("\n");}
printf("\n");
j = 2;
for (i = 0; i < 3; i++) {
mat[i][j] = 0;
j--;}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%d ",mat[i][j]);
printf("\n");}
i =1;
for (j = 0; j < 3; j++)
mat[i][j] =5;
printf("\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%d ",mat[i][j]);
printf("\n");}
printf("\n");
j=1;
for (i = 0; i < 3; i++)
mat[i][j] =5;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%d ",mat[i][j]);
printf("\n");}
printf("\n");
j=0;
for (i = 0; i < 3; i++) {
mat[i][j]=2;
i++;}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%d ",mat[i][j]);
printf("\n");}
printf("\n");
j = 1;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if(mat[i][j]==5)
cont++;
printf("cont =%d \n", cont);
return 0;
}
Sep 11, 2016 at 5:32am UTC
#include <stdio.h>
#include <stdlib.h>
int delete ( int v[5], int length, int pos) {
if ( pos == length-1) return 0;
v[pos] = v[pos +1];
delete(v,length,pos+1);
}
int main () {
int v[5];
int i;
int max;
double medie;
int n=0;
int suma=0;
for (i = 0; i < 5; i++) {
scanf ("%d", &v[i]);
while(v[i]<-1024 || v[i] >1023){
printf("eroare!introduceti alt nr");
scanf ("%d", &v[i]);
}
}
printf("vectorul este:\n");
for (i = 0; i < 5; i++)
printf("v[%d]=%d\n", i,v[i]);
max = v[0];
for (i = 0; i < 5; i++) {
if (max < v[i])
max = v[i];
}
printf ("max este:%d\n",max);
for (i = 0; i < 5; i++) {
suma =suma +v[i];
n++;
}
printf("suma=%d\n", suma);
printf( "nr elem=%d\n", n);
medie=(double)suma/n;
printf("media este:%lf\n", medie);
delete(v,5,2);
printf("vectorul nou este:\n");
for (i = 0; i < 5; i++)
printf("v[%d]=%d\n", i,v[i]);
return 0;
}