- Joined
- Sep 29, 2016
- Posts
- 1,600
- Solutions
- 6
- Reaction
- 1,480
- Points
- 649
Magandang araw mga master, pasuyo naman oh
Ito po yung code ko sa program na
Function that moves the sorted Multiple of 3 in descending order at the beginning followed by the sorted remaining numbers in ascending order.
Problema ko po san ko ilalagay ang (n%3==0) para sa Multiples of 3 na ma sort sa unahan.
Maraming salamat sa makakatulong
[CODE lang="c" title="Multiple of 3"]#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,n,i,j,temp;
printf("Enter size of array:\n");
scanf("%d",&n);
a=malloc(sizeof(int)*n);
printf("Enter %d Elements:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n/2;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(j=n/2;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Sorted Multiple of 3 in descending and remaining in ascending order:\n");
for(i=0;i<n;i++)
{
printf("%d ",a);
}
return 0;
}[/CODE]
Ito po yung code ko sa program na
Function that moves the sorted Multiple of 3 in descending order at the beginning followed by the sorted remaining numbers in ascending order.
Problema ko po san ko ilalagay ang (n%3==0) para sa Multiples of 3 na ma sort sa unahan.
Maraming salamat sa makakatulong
[CODE lang="c" title="Multiple of 3"]#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,n,i,j,temp;
printf("Enter size of array:\n");
scanf("%d",&n);
a=malloc(sizeof(int)*n);
printf("Enter %d Elements:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n/2;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(j=n/2;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("Sorted Multiple of 3 in descending and remaining in ascending order:\n");
for(i=0;i<n;i++)
{
printf("%d ",a);
}
return 0;
}[/CODE]