View Full Version : some one correct me this program


system_eyes
hi friends, i was solving some exercises with c (making revision)then i write this program but the problem that there were an errors duraing the compilation, i wonder if some one can correct me, the program is to determine the smallest value in the multible subscripted array
thanks

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

void sort1 (int[][5]);
void sort2 (int[][5]);
void getsmall (int,int);
int main()
{
int t[2][5] = { {2,3,2,1,0} , {9,3,4,32,2} } ;
sort1(t);
sort2(t);
getsmall(t[0][0],t[1][0]);
return 0;
getch();
}
void sort1 (int b[][5])
{
int hold = 0 ;

for(i= 0 ,i != 4 ,i++ )
for(j=0,j!=4,j++)
if(b[0][j] > b[0][j+1]){
hold = b[0][j];
b[0][j] = b[0][j+1];
b[0][j+1] = hold;
}

}

void sort2 (int b[][5])
{
int hold = 0 ;int j;int i;
for(i= 0,i!= 4,i++)
for(j=0,j!=4,j++)
if(b[1][j] > b[1][j+1]){
hold = b[1][j];
b[1][j] = b[1][j+1];
b[1][j+1] = hold;
}
}

void small(int a,int b)
{
int small = 0;
if(a > b)
small = b;
else
small = a;

printf("the smallest value is %d",small);
}

OneOfOne
#include <stdio.h>
//#include <conio.h>

void sort1 (int[][5]);
void sort2 (int[][5]);
void getsmall (int,int);

int main()
{
int t[2][5] = { {2,3,2,1,0} , {9,3,4,32,2} } ;
sort1(t);
sort2(t);
getsmall(t[0][0],t[1][0]);
return 0;
getch();
}
void sort1 (int b[][5])
{
int hold = 0 ;
int i,j;
for(i= 0;i < 5 ;i++ )
for(j=0;j < 5;j++)
if(b[0][j] > b[0][j+1]){
hold = b[0][j];
b[0][j] = b[0][j+1];
b[0][j+1] = hold;
}

}

void sort2 (int b[][5])
{
int hold = 0 ;int j;int i;
for(i= 0;i < 5;i++)
for(j=0;j < 4;j++)
if(b[1][j] > b[1][j+1]){
hold = b[1][j];
b[1][j] = b[1][j+1];
b[1][j+1] = hold;
}
}

void getsmall(int a,int b)
{
int small = 0;
if(a > b)
small = b;
else
small = a;

printf("the smallest value is %d\n",small);
}
i can't believe that anyone sucks in C more than i do.. :p

peace

Aljaber
Asslamo 3laykom

plz kill conio.h first it is not ANSI and not POSIX

then function definition at the bottom of the code must be for getsmall() not small()

peace be upon you

Aljaber
Asslamo 3laykom

OneOfOne i think gentoo makes you too fast , LOL


peace be upon you

OneOfOne
Originally posted by Aljaber
Asslamo 3laykom

OneOfOne i think gentoo makes you too fast , LOL


peace be upon you
yeppers :D
you also forgot about for()
he had it (x, x, x), it shoulda been (x ; x ; x)
;) :)

peace

uniball
return 0;
getch ();

A function call after return 0; ?
Are you serious ??
conio.h is used by borland's compiler.
+ the other comments by all the posts above and below this :-)
I didn't test the code yet.

MaherG
use BBCODE please,
[ CODE ]

.
.
.
.

[ /CODE ]

w/o the spaces

Maher