Question

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void main(void){
int x[20][20],n,i,j,min,minj,max,maxi,maxj,aux;
char z;
clrscr();
printf("\nCulegeti marimea masivului 3<n<20");
scanf("%d",&n);
label:clrscr();
printf("\n\nAlegeti metoda de completare a masivului(a/m):\n");
printf("\n a-Automat\n");
printf("\n m-Manual\n");

z=getch();
if((z=='a')||(z=='A')) goto automat;
else
if((z=='m')||(z=='M')) goto manual;
else goto label;
automat:randomize();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
x[i][j]=random(19);
}
}

goto masiv;
manual:printf("\nCulegeti masivul x[%d][%d]\n",n,n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("x[%d][%d]=",i,j);
scanf("%d",&x[i][j]);
}
}

masiv:clrscr();
printf("\nMasivul x[%d][%d] initial:\n\n",n,n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%3d",x[i][j]);
}
printf("\n\n");
}

min=x[3][0];minj=0;
for(j=0;j<n;j++)
if(x[3][j]<min){min=x[3][j];min=j;}
printf("\nElementul minimal de pe rindul 3 estex[3][%d]=%d\n",minj,min);
printf("indicati coloana dorita ");
scanf("%d",&maxj);
max=x[0][max];maxi=0;
for(i=0;i<n;i++)
if(x[i][maxj]>max){
max=x[i][maxj];
maxi=i;
}

printf("\nElementul maximal de pe coloana %d este x[%d][%d]=%d\n",maxj,maxi,maxj,max);
aux=x[3][minj];
x[maxi][maxj]=aux;
printf("\nMasivul x[%d][%d] final:\n\n",n,n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%3d",x[i][j]);
}

printf("\n\n");
}

printf("\nElementul maximal de pe coloana indicata a fost schimbat\n");
printf("cu elementul minimal %d de pe rindul 3",min);
getch();
}



what should I exactly change here so that the elements of each coloumn to be arranged in increasind order?
goto?
closed account (z05DSL3A)
First edit your post... put [code] at the stat of you code and [/code] at the end, it will then be easier to read.
closed account (S6k9GNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void main(void){
int x[20][20],n,i,j,min,minj,max,maxi,maxj,aux;
char z;
clrscr();
printf("\nCulegeti marimea masivului 3<n<20");
scanf("%d",&n);
label:clrscr();
printf("\n\nAlegeti metoda de completare a masivului(a/m):\n");
printf("\n a-Automat\n");
printf("\n m-Manual\n");

z=getch();
if((z=='a')||(z=='A')) goto automat;
else
if((z=='m')||(z=='M')) goto manual;
else goto label;
automat:randomize();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
x[i][j]=random(19);
}
}

goto masiv;
manual:printf("\nCulegeti masivul x[%d][%d]\n",n,n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("x[%d][%d]=",i,j);
scanf("%d",&x[i][j]);
}
}

   masiv:clrscr();
   printf("\nMasivul x[%d][%d] initial:\n\n",n,n);
   for(i=0;i<n;i++)
   {
      for(j=0;j<n;j++)
      {
         printf("%3d",x[i][j]);
      }
      printf("\n\n");
   }
   min=x[3][0];minj=0;
   for(j=0;j<n;j++)
      if(x[3][j]<min){ min=x[3][j];min=j; }
   printf("\nElementul minimal de pe rindul 3 estex[3][%d]=%d\n",minj,min);
   printf("indicati coloana dorita ");
   scanf("%d",&maxj);
   max=x[0][max];maxi=0;
   for(i=0;i<n;i++)
      if(x[i][maxj]>max)
      {
         max=x[i][maxj];
         maxi=i;
      }

   printf("\nElementul maximal de pe coloana %d este x[%d][%d]=%d\n",maxj,maxi,maxj,max);
      aux=x[3][minj];
      x[maxi][maxj]=aux;
      printf("\nMasivul x[%d][%d] final:\n\n",n,n);
      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
            printf("%3d",x[i][j]);
   }

   printf("\n\n");
}

   printf("\nElementul maximal de pe coloana indicata a fost schimbat\n");
   printf("cu elementul minimal %d de pe rindul 3",min);
   getch();
}
Topic archived. No new replies allowed.