View Full Version : HELP sa program [merging arrays]


fao_23
7th Apr 2010 Wed, 08:18
guys, patulong naman...

a function ng dalawang arrays na may lamang numbers

tapos imerge sila at isort sila in ascending order in another array...

Hintay ko po reply nyo, thanx...

(hindi po two-dimensional ang array)

Sa MERGE function ko po siya ilalagay...

eto po code ko:

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

#define maxsize 10


void merge();

main()
{
int arr1[maxsize],arr2[maxsize];
int i,x,e=0,o=0;
char let;
clrscr();
for(i=0;i<maxsize;i++){
printf("\n\nEnter number: ");
scanf("%d",&x);
if(x%2==0){
arr1[e] = x;
e++;
}else{
arr2[o] = x;
o++;
}
while(i!=9){
printf("\nAdd another number[Y/N]?");
let=tolower(getche());
if(let=='n' || let=='y'){
break;
}
else if(let!='y' && let!='n'){
printf("\nError!");
}
}
if(let=='n'){
break;
}


}

getch();
}



void merge()

Eko209
7th Apr 2010 Wed, 08:39
san ba yan sa C++, Pascal o VBasic?

In C, ganito magiging structure. Wala ako compiler so kung may sytax error/redundancey kayo na lang mag correct.


int array_1[5][5];
int array_result[25];

sort_ascending()
{
int i, x, HIGH_VAL, result_pointer;

HIGH_VAL = 0;
*sets the current value for highest number to be compared to the value of the array being scanned*

result_pointer = 1;
*counter for ---> array_result[result_pointer]*

for (i=1; i<=5; i++) *array row loop*
{
for (x=1; x<=5; x++) *array column loop*
{

if (array_1[i][x] > HIGH_VAL)

*if condition to scan if the current array holds the highest number*
{
HIGH_VAL = array_1[i][x];
*stores the highest number in memory if conditions are met*
array_result[result_pointer] = array_1[i][x];
*moves the highest value to the new array*
array_1[i][x] = 0; *zeros the value of the first array so that it won't be used again*
result_pointer = result_pointer + 1;
*moves the counter for the array_result*
}
else
{
result_pointer = result_pointer + 1;
*moves the counter for the array_result*
}

}
}
}

Sana makatulong.

fao_23
7th Apr 2010 Wed, 08:50
san ba yan sa C++, Pascal o VBasic?

Turbo C po

vernonengle
8th Apr 2010 Thu, 22:14
1. reate an array na ang size ay double ng maxsize (ito magiging sorted array)
2. icopy mo ang laman ng dalawang array using loops sa magiging sorted array (nested, outer loop ay para sa magiging sorted array, inner loop para sa dalawang kinopyang array).
3. do any sorting algorithm sa magiging sorted array(insertion sort pinakamaiksi para sakin, bubble sort ang usual na ginagamit ng beginners)