CaCao
28/10/2007, 10:56
selam arkadaslar
programda girilen sayilarin positif ve negatif olarak ayirmasi lazim ve bu programin -100 ile 100 arasinda calismasi lazim ama olmuyo bi turlu
umarim yardim edebilirsiniz.
cikti soyle olucak:
Enter array elements: 2 3 0 -9 12 -15 0 4 9 101
Psitive numbers: 2 3 12 4 9
Negative numbers: -9 -15
/**********************function seperate***************************/
void separete(int ary[],int size, int n_ary[],int p_ary[],int *j, int *k)
{
int i=0;
*j=0; *k=0;
for(i=0;i<size;i++)
{
if(ary[i]>0)
p_ary[*j]=ary[i];
(*j)++;
}
for(i=0;i<size;i++)
{
n_ary[*k]=ary[i];
(*k)++;
}
}
/**********************Main************************ **/
int
main(void)
{
int ary[SIZE], //array in program
i, //loop
n_ary[SIZE], //negative values array
p_ary[SIZE], //positive array
j, //index for positive elemens
k; //index for negative elemens
i=0;
n_ary[i]=0;
p_ary[i]=0;
/*get the elements in an array*/
printf("Enter array elements:");
scanf("%d",&ary[i]);
while(i<SIZE && ary[i]>-100)
{
i++;
scanf("%d",&ary[i]);
}
/*call the function*/
separete(ary,i,n_ary,p_ary,&j,&k);
//print the positive arrays
printf("\nPositive numbers: ");
for(i=0;i<j;i++)
{
printf("%d ",p_ary[j]);
}
//print the negative values
printf("\nNegative numbers: ");
for(i=0;i<k;i++)
{
printf("%d ",n_ary[k]);
}
printf("\n");
system("pause");
return(0);
}
programda girilen sayilarin positif ve negatif olarak ayirmasi lazim ve bu programin -100 ile 100 arasinda calismasi lazim ama olmuyo bi turlu
umarim yardim edebilirsiniz.
cikti soyle olucak:
Enter array elements: 2 3 0 -9 12 -15 0 4 9 101
Psitive numbers: 2 3 12 4 9
Negative numbers: -9 -15
/**********************function seperate***************************/
void separete(int ary[],int size, int n_ary[],int p_ary[],int *j, int *k)
{
int i=0;
*j=0; *k=0;
for(i=0;i<size;i++)
{
if(ary[i]>0)
p_ary[*j]=ary[i];
(*j)++;
}
for(i=0;i<size;i++)
{
n_ary[*k]=ary[i];
(*k)++;
}
}
/**********************Main************************ **/
int
main(void)
{
int ary[SIZE], //array in program
i, //loop
n_ary[SIZE], //negative values array
p_ary[SIZE], //positive array
j, //index for positive elemens
k; //index for negative elemens
i=0;
n_ary[i]=0;
p_ary[i]=0;
/*get the elements in an array*/
printf("Enter array elements:");
scanf("%d",&ary[i]);
while(i<SIZE && ary[i]>-100)
{
i++;
scanf("%d",&ary[i]);
}
/*call the function*/
separete(ary,i,n_ary,p_ary,&j,&k);
//print the positive arrays
printf("\nPositive numbers: ");
for(i=0;i<j;i++)
{
printf("%d ",p_ary[j]);
}
//print the negative values
printf("\nNegative numbers: ");
for(i=0;i<k;i++)
{
printf("%d ",n_ary[k]);
}
printf("\n");
system("pause");
return(0);
}